【问题标题】:Laravel remove backslashes from JSON response in Restful APILaravel 从 Restful API 中的 JSON 响应中删除反斜杠
【发布时间】:2020-12-01 00:37:33
【问题描述】:

我正在构建一个 restful api,我正在尝试传递存储在数据库中的图像 URL

例如,当我尝试将此链接传递给 api 127.0.0.1:8000/images/123.jpg 时,它看起来像 127.0.0.1:8000\/images\/123.jpg

我尝试了stripslashes() 之类的方法,但没有任何效果

控制器

public function companiesAll()
{
    $companies = Company::where('status',1)->select('id', 'name',"image")->get();

        return response()->json([$companies]);
}

【问题讨论】:

  • 您需要解析front-end 上的JSON,它会自动去除这些斜线
  • @BasheerKharoti 请给我一个例子
  • 更新您的代码并包括您调用 API 的位置(Ajax 请求)
  • @BasheerKharoti Dude,这是一个用于移动应用的 Restful API!
  • 无论是什么 API,您都会在某处使用它

标签: php json laravel api laravel-5


【解决方案1】:

尝试使用:

return response()->json($companies, 200, [], JSON_UNESCAPED_UNICODE);

【讨论】:

    猜你喜欢
    • 2020-05-11
    • 2018-06-01
    • 2013-01-17
    • 2019-10-16
    • 1970-01-01
    • 2018-08-23
    • 2018-12-02
    • 2012-12-21
    • 2016-12-05
    相关资源
    最近更新 更多