我在解碼JSON數據時遇到問題。 有人不明白爲什麼變量$clanid
沒有設置?json_decode無法正常工作
這是代碼:
$url = "http://185.112.249.77:9999/Api/Search?search=&level=1&min=1&max=50&points=48000";
$jsondata = file_get_contents($url);
$data = json_decode($jsondata, true);
foreach ($data->clanList as $clan) {
$clanid = $clan->id;
echo $clan->id;
}
在此先感謝您的幫助。
Protip:'var_dump($ data);'。這是你所期望的嗎? –
爲什麼傳遞'true'並不知道它在做什麼? – AbraCadaver
RTFM:http://php.net/json_decode第二個參數:'當TRUE時,返回的對象將被轉換爲關聯數組。你迫使PHP返回一個數組,然後嘗試將該數組視爲一個對象。 –