好的,所以我正在尝试解析Foursquare返回的数据,以获取GET请求以返回场地详细信息。以下是我需要解析的响应部分:
{"meta":{"code":200,"errorType":"deprecated","errorDetail":"Please provide an API version to avoid future errors.See http:\/\/bit.ly\/vywCav"},"response":{"venue":{"id":"4b522afaf964a5200b6d27e3","name":"The Woodville","contact":{"phone":"+442920397859","formattedPhone":"+44 29 2039 7859","twitter":"woodvillelovers"},"location":{"address":"1 - 5 Woodville Rd.","lat":51.49051570871893,"lng":-3.1805795431137085,"postalCode":"CF24 4DW","city":"Cardiff","state":"Wales","country":"United Kingdom"}
这是我解析和显示此信息的代码:
$json = json_decode($response);
foreach ($json->response->venue as $result)
{
echo $result->name.' - '.$result->address.' '.$result->city."<p />";
}
我得到的错误是foreach中的行是'试图获取非对象的属性'。我在这做错了什么?似乎无法看到问题。提前谢谢。
答案 0 :(得分:0)
这只是一个猜测,因为我不知道php,但可能是因为地址和城市不属于场地,而是位于场地 - >位置。
$json = json_decode($response);
foreach ($json->response->venue as $result)
{
echo $result->name.' - '.$result->location->address.' '.$result->location->city."<p />";
}