我正在創建一個php腳本來檢查某個人是否在Twitter上關注我,並且我正在使用REST API Method: friendships show method並使用themattHarris tmhOAuth庫進行OAuth。如何從Twitter JSON數組中提取值
我使用下面的代碼做出請求:
$code=$tmhOAuth->request('GET', $tmhOAuth->url('friendships/show'), array('target_screen_name' => 'bob'));
if ($code==200){ $code = json_decode($tmhOAuth->response['response'], true); }
該請求是成功的,並返回類似JSON輸出apiwiki頁所示:
{"relationship": { "source": { "id": 123, "screen_name": "bob", "following": true, "followed_by": false, "notifications_enabled": false }, "target": { "id": 456, "screen_name": "jack", "following": false, "followed_by": true, "notifications_enabled": null } } }
我的問題
如何從返回的數組中提取以下值?
"id": 456,
你[應該在發問前搜索(http://stackoverflow.com/questions/ask-advice):http://stackoverflow.com/搜索?q =讀取+ json + php](http://stackoverflow.com/search?q=read+json+php) – Gordon 2011-05-17 21:11:11
一旦您通過json_encode傳遞JSON數據,它只是一個普通的PHP數據結構。像訪問其他數組或對象一樣訪問數據。 – 2011-05-17 21:13:15