我在这方面仍然是个业余爱好者,但我学得真的很快。我有一个php索引,其中包含一个API请求,用于RIOT的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,它启用了print_r($json);,所有其他回波都被禁用了(完全相同的代码)。在第二个链接中,您可以看到可以在其上创建过滤器的项目。我想知道如何从这个数组中获取信息并回显它们。谢谢你花时间帮了个菜鸟。
发布于 2014-09-25 19:59:24
这可能是因为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'];
}https://stackoverflow.com/questions/26046203
复制相似问题