我使用laravel作为API
。我已经添加了striplash函数来删除斜杠。
$content = stripcslashes($raw["f_content"]);
它给我正确的结果,因为我想要。
但是当我在JSON
响应中发送它时,它会在此处转换为JSON
响应。
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": "jfkhelp@gmail.com",
"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"
}
答案 0 :(得分:2)
尝试
var finalData = str.replace(/\\/g, "");
alert(yourdata);
OR
json_encode($yourdata, JSON_UNESCAPED_SLASHES);
OR
echo str_replace('\/','/',json_encode($yourdata));
OR
您必须解码JSON
两次,例如
var data = JSON.parse(JSON.parse(json).yourdata));
希望这对你有所帮助!!