2011-06-08 48 views
2

嗨使用圖形API我能夠得到我的相冊的照片,現在我想下載到相冊中的所有照片到我的電腦。它以JSON格式返回數據,我怎麼纔可以過濾來自JSON的圖片的網址,然後從網址下載 所有照片我的JSON是一些類似這樣的格式使用JSON格式的圖表API下載Facebook照片?

{ 


"data": [ 
     { 
     "id": "1140894483853", 
     "from": { 
      "name": "Muhammad Asghar", 
      "id": "1272156814" 
     }, 
     "tags": { 
      "data": [ 
       { 
        "id": "1272156814", 
        "name": "Muhammad Asghar", 
        "x": 52.6, 
        "y": 29.538, 
        "created_time": "2009-08-20T07:46:50+0000" 
       } 
      ] 
     }, 
     "picture": "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v3356/171/103/1272156814/s1272156814_30392128_5890712.jpg", 
     "source": "http://a4.sphotos.ak.fbcdn.net/photos-ak-snc1/v3356/171/103/1272156814/n1272156814_30392128_5890712.jpg", 
     "height": 604, 
     "width": 498, 
     "images": [ 
      { 
       "height": 604, 
       "width": 498, 
       "source": "http://a4.sphotos.ak.fbcdn.net/photos-ak-snc1/v3356/171/103/1272156814/n1272156814_30392128_5890712.jpg" 
      }, 

請任何人的幫助。

+3

試試json_decode? http://php.net/manual/en/function.json-decode.php – AllisonC 2011-06-08 14:20:40

回答

2

您可以使用JsonDecode:JsonDecode 假設你的JSON字符串是在$data變量,你可以嘗試這樣的事:

<?php 
var_dump(json_decode($data)); 
?> 

,如果你看一下網頁的源代碼,你將有一個關於json是如何構建的非常清晰的想法,並且您可以輕鬆地使用foreach語句來獲取您需要的url只需

+0

當我使用thi – Asghar 2011-06-08 15:21:46

+0

請告訴我如何循環此json以獲取源對象中的所有值 – Asghar 2011-06-08 15:24:12

+1

感謝它的幫助。它解決了我的問題 – Asghar 2011-06-09 09:14:18