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
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
Share Improve this question asked Nov 13, 2014 at 10:14 zeitgeistzeitgeist 431 gold badge1 silver badge7 bronze badges 03 Answers
Reset to default 3Your 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);
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);
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("|","");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744936989a4602087.html
评论列表(0条)