简体   繁体   English

尝试获取非对象错误JSON的属性

[英]Trying to get property of non-object error JSON

I'm trying to get the location of Instagram pictures from my account. 我正在尝试从我的帐户中获取Instagram图片的位置。 The API is giving me all sorts of information about my account and pictures, but when I try to get the location of my pictures it says: 该API为我提供了有关我的帐户和图片的各种信息,但是当我尝试获取图片的位置时,它会说:

Trying to get property of non-object in .... 试图获取非对象的属性。

My code looks like this: 我的代码如下所示:

foreach($phplijst->data as $data){
    echo "<img src=" . $data->images->low_resolution->url . " />";
    echo "<p>" . $data->location->longitude . "</p>";
}

The first "echo" gives me all the images from my account. 第一个“回声”给了我帐户中的所有图像。 The second "echo" is supposed to give me the longitude of all the images on my account. 第二个“回声”应该是给我帐户上所有图像的经度。 Instead it gives me that error message. 相反,它给了我该错误消息。 Does anyone know how to fix this? 有谁知道如何解决这一问题?

It means that $data->location isn't an object. 这意味着$data->location不是对象。
You should check your object structure with var_dump($data) and verify it has the layout you expect. 您应该使用var_dump($data)检查对象结构,并确认它具有所需的布局。

Never mind guys! 没关系,伙计们! I've fixed it. 我已经解决了。 I forgot to add a location to my images so that's why I didn't get a location :) Thanks for the help anyway! 我忘记在图像中添加位置,所以这就是为什么我没有位置的原因:)无论如何,感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM