1

我是 PHP 开发新手,需要您的帮助。我用 RIOT API编写了一个网页summerer-info.com 。但是我很难理解文档。我想通过回显我的状态来输出。在 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 "]]
4

1 回答 1

1

假设这是您期望的响应类型(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

希望有帮助!

于 2015-11-09T17:04:01.397 回答