2013-08-19 124 views
-2

我無法從使用PHP的JSON獲取「img_url」(在第三行)值。這裏的JSON字符串:如何解析這個JSON?

編輯(這是JSON,我對張貼的var_dump道歉)

{"status_code":200,"status_txt":"OK", 
"data":{"img_name":"KdxIC.png","img_url":"http:\/\/s0.uploads.im\/KdxIC.png", 
"img_view":"http:\/\/uploads.im\/KdxIC.png","img_width":"504","img_height":"504", 
"img_attr":"width=\"504\" height=\"504\"","img_size":"15.1 KB","img_bytes":15494, 
"thumb_url":"http:\/\/s0.uploads.im\/t\/KdxIC.png","thumb_width":360,"thumb_height":360, 
"source":"http:\/\/site.com\/uploads\/[email protected]","resized":"0","delete_key":"6e814d3c5201feee"}} 

接受的答案的作品。謝謝

+1

您的企圖解決方案在哪裏? – PeeHaa

+0

我從來沒有見過像那樣的JSON ......什麼是返回這些數據? – Justin

+5

這不是JSON(它可能是'json_parsing'在PHP中的一些JSON結果的轉儲)。 – Quentin

回答

2

該代碼不是json,它是一個數組的php轉儲。

如果要訪問圖像url,請執行以下操作:
我正在使用此example url

$imgdata = json_decode($response, true); 
echo $imgdata["data"]["img_url"]; 

輸出:

http://s0.uploads.im/go0WK.png 


編輯:
不要使用第二PARAM在json_decode,那是你的對象轉換爲數組。

+0

你是如何得到迴應的?我使用file_get_contents()但沒有運氣。 – Lukas

+1

我試過這個: $ img = json_decode(file_get_contents('http://uploads.im/api?upload=http://www.google.com/images/srpr/nav_logo66.png')); echo $ img-> data-> img_url; 而且效果很好! –

+0

謝謝!最後工作一路。 – Lukas