无法从json获取数据

时间:2015-03-24 00:02:41

标签: php json laravel

我需要获得品牌:“你好世界” 当我使用json发送帖子数据并使用

获取时
 $input = Input::all();

然后用

die(print_r($input));

这是写的

Array ([[], {brand: "hello world"}, [], 1427154586016])1

并且

我尝试使用json_encode并使用

die(print_r($encode));

{data: "{"brand":"Hello world"}", dc: "142715"}1

现在,如果我这样做

$ brand = $ encode ['data']或$ brand = $ encode ['brand']

我收到错误。 如何获得var $ brand的Hello world

1 个答案:

答案 0 :(得分:1)

当你应该使用 json_decode()时,看起来你正在使用 json_encode()。但是就像kamlesh指出的那样,你的原始JSON数据似乎不是有效的JSON,所以这对你没有帮助。 This wiki article has an example of valid syntax.

另外,如果你正在使用laravel,你可以使用辅助函数 dd(),它将 die() var_dump()自动为你,节省你一点时间。

希望这可以解决您的问题,但如果没有,read the docs for the Input。应该有一些东西让你走上正轨。