如何使用Jquery从Json字符串数据中删除双引号

时间:2015-08-03 12:13:44

标签: jquery ajax json

我的jQuery脚本如下:

jQuery.ajax({
    type:"GET",
    url:url, 
    data:'action=getStatus', 
}).done(function(response){ 
    var data = jQuery.parseJSON(response);

    var test = data['visitor_chart'];
})  

我的jQuery.ajax以下面的形式返回响应:

"{"visitor_chart":"{y: 3, label: \"2015-07-21\"}, {y: 1, label: \"2015-07-29\"}, {y: 1, label: \"2015-07-30\"}, {y: 1, label: \"2015-08-01\"}","visitor_count":6,"enquiry_count":1}"

parseJSON data['visitor_chart']后,我的"{y: 3, label: "2015-07-21"},{y: 1, label: "2015-07-29"},{y: 1, label: "2015-07-30"},{y: 1, label: "2015-08-01"}" 格式为:

/**
 * To rotate bitmap on canvas
 *
 * @param canvas         : canvas on which you are drawing
 * @param handBitmap     : bitmap of hand
 * @param centerPoint    : center for rotation
 * @param rotation       : rotation angle in form of seconds
 * @param offset         : offset of bitmap from center point (If not needed then keep it 0)
 */

public void rotateBitmap(Canvas canvas, Bitmap handBitmap, PointF centerPoint, float rotation, float offset) {
    canvas.save();
    canvas.rotate(secondRotation - 90, centerPoint.x, centerPoint.y);
    canvas.drawBitmap(handBitmap, centerPoint.x - offset, centerPoint.y - handBitmap.getHeight() / Constants.INTEGER_TWO, new Paint(Paint.FILTER_BITMAP_FLAG));
    canvas.restore();
}

但我想从这个字符串中删除第一个和最后一个引号。

怎么做?

1 个答案:

答案 0 :(得分:0)

替换第一个引用:

str=str.replace(/^"/, "");

替换最后一句:

str=str.replace(/"$/, "");

Verified here. It's working