Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove double quotes from Json string data using Jquery

Tags:

json

jquery

ajax

My jQuery script as below:

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:

"{"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:

"{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?

like image 461
Vinaya Maheshwari Avatar asked Jul 13 '26 00:07

Vinaya Maheshwari


1 Answers

to replace first quote :

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

to replace last quote :

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

Verified here. It's working

like image 148
dpanshu Avatar answered Jul 15 '26 15:07

dpanshu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!