简体   繁体   English

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

[英]How to remove double quotes from Json string data using Jquery

My jQuery script as below:我的 jQuery 脚本如下:

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

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

My jQuery.ajax return response in below form:我的 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}"

After parseJSON I got data['visitor_chart'] in below form: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"}"

but I want to strip first and last quote from this string.但我想从这个字符串中去掉第一个和最后一个引号。

How to do that?怎么做?

to replace first quote :替换第一个引用:

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

to replace last quote :替换最后一个报价:

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

Verified here.在这里验证。 It's working它正在工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM