0
enter code here
此代碼返回該錯誤是如何從Riot API爲召喚者創建此變量有什麼問題?
「試圖獲得非對象的財產」或「消息:未定義的屬性:stdClass的:: $名稱」。
變量$ summoner是什麼不起作用。假設變量sID,$ lcaseregion和$ APIkey(等)都已正確設置。
<?php
$summonerURL = "https://$lcaseRegion.api.pvp.net/api/lol/$lcaseRegion/v1.4/summoner/" . $sID . "?api_key=9" . $APIkey;
$responseSummoner = @file_get_contents($summonerURL);
$summoner = @json_decode($responseSummoner);
echo print_r($summoner); //this works and prints things
echo $summoner->name; //this does not work
echo $summoner->profileIconId; //this also does not work.
//please find print_r results below...
?>
print_r results;
stdClass Object ([41245441] => stdClass Object ([id] => 41245441 [name] => Bubbalubagus [profileIconId] => 558 [revisionDate] => 1488775287000 [summonerLevel] => 30))
任何其他意見和建議,你可以給我如何陣列的工作也將不勝感激。
這個問題的成功,對我來說,意味着成功地打印profileIconId(一個數字)和名稱以及stdClass對象數組中的任何其他內容。 – Bubbalubagus
這是對象的對象,可以用'foreach'或'pop' –