2012-03-09 64 views
0

好的,我試圖解析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是'試圖獲得非客體的財產'。我在這裏做錯了什麼?似乎無法看到問題。提前致謝。

回答

0

這只是一個猜測,因爲我不知道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