2012-03-19 115 views
0

我已經搜索堆棧溢出和谷歌的答案,但不是運氣。我試圖在下面的示例(facebook圖api)中使用php獲取每個語言環境的值。任何幫助,將不勝感激。PHP解析Facebook的json

"data": [ 
    { 
     "id": "123456789/insights/page_fans_locale/lifetime", 
     "name": "page_fans_locale", 
     "period": "lifetime", 
     "values": [ 
     { 
      "value": { 
      "en_US": 33975, 
      "fr_CA": 6906, 
      "fr_FR": 6105, 
      "en_GB": 5647 
      }, 
      "end_time": "2012-03-14T07:00:00+0000" 
     }, 
     { 
      "value": { 
      "en_US": 33992, 
      "fr_CA": 6906, 
      "fr_FR": 6107, 
      "en_GB": 5648 
      }, 
      "end_time": "2012-03-15T07:00:00+0000" 
     }, 
} 
+0

這是我試過到目前爲止: \t $ fb_response = json_decode($ graph_url); \t $ iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($ fb_response)); \t \t 的foreach($迭代爲$密鑰=> $值){ \t \t \t回聲 「」 $鍵 「
」 $值 「
」。; } – 2012-03-19 04:28:50

+0

有了這個我可以擁有所有的鍵和值,但我triyng只有語言環境和值。 – 2012-03-19 04:31:44

+0

似乎被打破了json – Arfeen 2012-03-19 05:03:49

回答

0

首先,這個片斷被破壞。 data是一個不是JavaScript對象的數組。 採取正確的片段並正確分析數據。最好的辦法是:

json_decode(); 

Here is how to use it.