Reputation: 43
I send data via ajax so:
$res = array();
foreach($series as $i){
//print_r($i);
array_push($res, $i);
}
//print_r ($res);
print (json_encode($res, JSON_UNESCAPED_SLASHES));
Get data:
success: function(json){
alert(JSON.stringify(json));
json = json.replace("\\", " ");
alert(JSON.stringify(json));
It is alerting same datas, why? How can I remove slashes from json? Thanks
Upvotes: 1
Views: 10715
Reputation: 646
First of all you have to parse your string and after that you can use json.replace
var obj = jQuery.parseJSON( '{ "name": "John\\" }' );
var myname=obj.name ;
myname.replace("|","");
Upvotes: 0
Reputation: 11859
json.stringify
returns the data as string.so you need to parse it to get in array format which will remove slashes automatically.
var data = JSON.parse(json);
alert(data);
console.log(data);
Upvotes: 0
Reputation: 4032
Your PHP code returning JSON in to String not in Object
Use JSON.parse
instead of JSON.stringify()
Replace success function like this:
success: function(json){
alert(JSON.parse(json));
//json = json.replace("\\", " ");
alert(json);
console.log(json);
Upvotes: 3