Laravel。 Response内容必须是实现__toString()的字符串或对象," boolean"特定

时间:2016-03-12 11:38:13

标签: php laravel laravel-5

这是我的阵列。

http://pastebin.com/eTrJ2PVB

当我像这样返回这个数组时,我收到一个错误。

return \Response::json($response, 200, [], JSON_NUMERIC_CHECK);

但是,当我删除JSON_NUMERIC_CHECK时,我得到了响应;但问题是我需要数值。

可以做些什么来解决这个问题?

1 个答案:

答案 0 :(得分:0)

You don't mention what error you are getting, but I can't reproduce any errors either. In fact this code at http://pastebin.com/GJWrCgwN shows your array returned as a perfectly formatted JSON with literal numbers instead of strings - see results at http://pastebin.com/cYDzDGyE.

BTW, you can also use this alternative syntax where you don't need to mess with HTTP response status code or headers, just the JSON encoding options:

return response()->json($response)->setEncodingOptions(JSON_NUMERIC_CHECK);

Check it out at Symfony\Component\HttpFoundation\JsonResponse.