无法解码有效的json格式,Response内容必须是实现__toString()," object"的字符串或对象。特定

时间:2017-05-21 23:01:04

标签: arrays json laravel object

我有一个有效的json格式{"active":"false","period":"23-05-2017 to 25-05-2017","percentage":null,"value":null,"status":"inc","fixed_price":null}但是,当我尝试解码时,它会返回错误

  

Response内容必须是实现__toString()," object"的字符串或对象。给出。

我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

将你的json函数包装在'中。结果使用$json = '{"active":"false","period":"23-05-2017 to 25-05-2017","percentage":null,"value":null,"status":"inc","f‌​ixed_price":null}'

注意开放和关闭。然后你可以调用json_decode($ json)

这是工匠修补匠的完整结果:

>>> $json = '{"active":"false","period":"23-05-2017 to 25-05-2017","percentage":null,"value":null,"status":"inc","fixed_price":null}'
=> "{"active":"false","period":"23-05-2017 to 25-05-2017","percentage":null,"value":null,"status":"inc","fixed_price":null}"
>>> json_decode($json);
=> {#869
 +"active": "false",
 +"period": "23-05-2017 to 25-05-2017",
 +"percentage": null,
 +"value": null,
 +"status": "inc",
 +"fixed_price": null,
   }