如何解析由Foursquare返回的JSON

问题描述:

好的,我试图解析Foursquare返回的GET请求返回场地详细信息的数据。这里是响应我需要解析的部分:如何解析由Foursquare返回的JSON

{"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是'试图获得非客体的财产'。我在这里做错了什么?似乎无法看到问题。提前致谢。

这只是一个猜测,因为我不知道PHP,但也许这是因为地址和城市不属于场地,但在场地 - >位置下。

$json = json_decode($response); 
foreach ($json->response->venue as $result) 
{ 
    echo $result->name.' - '.$result->location->address.' '.$result->location->city."<p />"; 
} 
+0

感谢您的回应,但我仍然得到同样的错误。我不知道如何解析这些信息,这对我的工作至关重要! – 2012-03-10 20:04:11