簡體   English   中英

如何回顯 PHP HashMaps

[英]How to echo PHP HashMaps

我是 PHP 開發新手,需要您的幫助。 我用 RIOT API 編寫了一個網頁senter-info.com 但是我很難理解文檔。 我想通過 echo my states 輸出。 在 API 文檔中:

返回值:地圖[字符串,列表[LeagueDto]]

但我不明白如何使用它。

文檔鏈接:鏈接

我寫了這個

$url = "https://{$region}.api.pvp.net/api/lol/{$region}/v2.5/league/by-summoner/{$summoner_ID}?api_key={$api}";
$data = file_get_contents($url);
$data = json_decode($data, true);
print_r($data);

所以我怎么能寫這樣的東西

echo $data["tier"["LeagueDto "]]

假設這是您期望的響應類型(2 個召喚師 ID):

https://github.com/josephyi/taric/blob/master/spec/fixtures/leagues_by_summoner_ids.json

JSON 響應中沒有 LeagueDto 條目。 當 Riot 引用 'LeagueDto' 時,它是代表對象數據的類,但並不意味着可以從響應中訪問。 如果您查看響應,則必須導航 JSON。 我不懂 PHP,但假設你想要召喚師 ID 21066:

$data["21066"] // array of leagues the summoner is in
$data["21066"][0] // first league the summoner is in
$data["21066"][0]["entries"] // array of league entries for the first league
$data["21066"][0]["tier"] // tier of first league

希望有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM