如何在laravel中从json响应中删除斜杠

如何在laravel中从json响应中删除斜杠,json,laravel,Json,Laravel,我将laravel用于API。我已经添加了stripslash函数来删除斜杠 $content = stripcslashes($raw["f_content"]); 这会给我想要的正确结果。 但是当我在JSONresponse中发送它时,它将在slashe中转换,这里是JSONresponse return response()->json($body); { "f_id": 1, "f_content": "comment's \"Hi\"",

我将laravel用于
API
。我已经添加了stripslash函数来删除斜杠

$content = stripcslashes($raw["f_content"]);
这会给我想要的正确结果。 但是当我在
JSON
response中发送它时,它将在slashe中转换,这里是
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": "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"
}
试一试

您必须将
JSON
解码两次,例如:

var data = JSON.parse(JSON.parse(json).yourdata));

希望这些都能对你有所帮助

尝试:
str.replace(/\\\/g,”)如:
var finalData=str.replace(/\\\/g,”);警报(最终数据)让我知道这是否有效!然后尝试:
JSON.parse(JSON.parse(JSON.data))使用数据或您在
JSON.parse(JSON.data)
中拥有的任何数据!需要斜杠来提供有效的JSON,JSON解码应该删除斜杠。斜杠用于转义“表示它是字符串的一部分,不用于封装字符串。\”将导致“解码后”,或者您也可以尝试:
echo str\u replace('\/','/',json\u encode($mydatas));
json_encode($yourdata, JSON_UNESCAPED_SLASHES);
echo str_replace('\/','/',json_encode($yourdata));
var data = JSON.parse(JSON.parse(json).yourdata));