Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 在Laravel中显示JSON变量值_Arrays_Json_Laravel - Fatal编程技术网

Arrays 在Laravel中显示JSON变量值

Arrays 在Laravel中显示JSON变量值,arrays,json,laravel,Arrays,Json,Laravel,我在最近的Laravel 4.1项目中收到了这个消息,我相信这是一个JSON回报 {"id":5,"owner":"2","message":"What a wonderful shoot today in Belgium!","post_at":"2","created_at":"2014-02-25 15:05:50","updated_at":"2014-02-25 19:05:50"} 但是我通常可以这样显示它: echo $post->id; 但不知何故,它没有返回“5”,而

我在最近的Laravel 4.1项目中收到了这个消息,我相信这是一个JSON回报

{"id":5,"owner":"2","message":"What a wonderful shoot today in Belgium!","post_at":"2","created_at":"2014-02-25 15:05:50","updated_at":"2014-02-25 19:05:50"}
但是我通常可以这样显示它:

echo $post->id;
但不知何故,它没有返回“5”,而是什么也没有返回。 但是当我使用
$post->toArray()转换为数组时并尝试使用
echo$post['id']查看它成功返回“5”

使用
echo$post->id返回其值的最佳方式是什么?我还尝试使用
$post->toJSON()确保变量为JSON但仍返回空。

检查此项

$post=post::where('id','=',5)->get()(不要忘记get())

$post=post::where('id',5)->get()(不要忘记get())

$post=post::find(5); 回答可能是:

Response::json($post);
答复:json($员额);如果您想像对象一样访问它,为什么要将其作为JSON返回?也就是说,既然它是JSON,
JSON\u decode
,就是您要查找的内容:。这将把JSON转换为stdClass object.Awesome。它工作得很好!我从一个服装模型类中获得了JSON,该类带有query
static::where('owner',$meandfriends)->orderby('updated_at','desc')->get()
您的查询已经过测试,并且运行正常,但这不是我的意思,不过感谢我现在意识到了这一点,我应该这样返回:
如果(!is_null('stream=static::where('owner',$meandfriends)->orderby('updated_at','desc')->get()){return json_decode($stream)}
而不是:
如果(!is_null($stream=static::where('owner',$meandfriends)->orderby('updated_at','desc')->get()){return$stream;}
他想在模板中正确地执行,而不是用jQuery。 $post = Post::where('id',5)->get() $post = Post::find(5); Response::json($post);
   $.get('url', {'id': id}, function (obj) {
     var te=obj.id;
     alert(te);
   });