2015-11-23 50 views
-1

解析JSON我只需要分析JSON:PHP和返回對象

object(stdClass)#363 (3) 

    { 
     ["type"]=> string(8) "champion" 
     ["version"]=> string(6) "5.22.3" 
     ["data"]=> object(stdClass)#362 (127) { 
      ["Thresh"]=> object(stdClass)#366 (4) { ["id"]=> int(412) ["key"]=> string(6) "Thresh" ["name"]=> string(6) "Thresh" ["title"]=> string(18) "Garde aux chaînes" } 
      ["Aatrox"]=> object(stdClass)#365 (4) { ["id"]=> int(266) ["key"]=> string(6) "Aatrox" ["name"]=> string(6) "Aatrox" ["title"]=> string(17) "Épée des Darkin" } 
      ["Tryndamere"]=> object(stdClass)#368 (4) { ["id"]=> int(23) ["key"]=> string(10) "Tryndamere" ["name"]=> string(10) "Tryndamere" ["title"]=> string(11) "Roi barbare" } etc... 

如何使用對象返回解析所有從這個JSON用PHP DATAS。

在此先感謝您的幫助。

+3

我不知道你在問什麼。請提供一個示例輸入(根據我的理解,JSON),您已經嘗試過的代碼以及當前和預期的輸出。 –

回答

1

使用json_decode。

返回的對象:

json_decode($json_string); 

返回的關聯數組:

json_decode($json_string, true); 
+0

你在OP的問題中看到哪些JSON字符串? – Rizier123

0

從我猜你用json_decode,它返回的對象。現在,您可以使用變量名訪問對象的值假設是$ var

echo $var->type; // will output champion 

您也可以通過提供第二個參數設置爲true

,那麼你可以通過

echo $var['type']; 
訪問此數據轉換JSON到數組
+0

是的:)我的錯誤謝謝:P – Robert