响应JSON结果(RIOT API)


Echoing JSON results (RIOT API)

我在这方面还是个业余爱好者,但我学得很快。我有一个php索引,其中包含对RIOT的API(英雄联盟)的API请求。我试图过滤结果,但当我尝试时,它会给我一个空白页。

这是我试图用来回显json结果的代码:

<html>
 <head>
  <title>RIOT API SBOX</title>
 </head>
 <body>
 <?php
$json = json_decode(file_get_contents('https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/31827832?api_key=mykey'), true);
//print_r($json);
echo $json[0]['rank'];
echo $json[0]['tier'];
echo $json[0]['wins'];
 ?> 
 </body>
</html>

我在这个网站上有一个实时预览:http://20ff.net/(此链接使用上面显示的代码)这是第二个链接http://20ff.net/index2.php其启用了CCD_ 1并且禁用了所有其他回波(具有完全相同的代码)。在第二个链接中,您可以看到可以创建过滤器的项目。我想知道如何从这个数组中获取信息并对其进行响应。谢谢你花时间帮助一个新手。

这可能是因为ssl证书将curl与CURLOPT_ssl_VERIFYPEER一起使用为FALSE

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/31827832?api_key=mykey');
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Get the response and close the channel.
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response, true);
foreach($json as $elem){
    echo $elem[0]['name'];
    echo $elem[0]['tier'];
}