Reputation: 256
I use laravel for API
. I already add stripslash function to remove slashes.
$content = stripcslashes($raw["f_content"]);
its give me proper result as I want.
but when I send it in JSON
response it will convert in slashe back here it is JSON
response.
return response()->json($body);
{
"f_id": 1,
"f_content": "comment's \"Hi\"",
"f_rant_id": 14,
"f_user_id": 1,
"upvote": 0,
"downvote": 0,
"f_image_url": null,
"f_status": 0,
"updated_at": {
"date": "2017-12-11 17:55:22.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"created_at": {
"date": "2017-12-11 17:55:22.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"f_email": "[email protected]",
"f_name": "",
"f_password": null,
"f_facebook_id": "531515500542146",
"first_name": "Kyle",
"last_name": "Wal",
"party_name": null,
"evericode": 0,
"f_last_logintime": "2017-12-11 17:55:22"
}
Upvotes: 2
Views: 5626
Reputation: 5042
Try
var finalData = str.replace(/\\/g, "");
alert(yourdata);
OR
json_encode($yourdata, JSON_UNESCAPED_SLASHES);
OR
echo str_replace('\/','/',json_encode($yourdata));
OR
You have to decode the JSON
twice, e.g.
var data = JSON.parse(JSON.parse(json).yourdata));
Hope any of this will helps you!!
Upvotes: 5