[英]PHP 7 Fatal error: Uncaught Error: Cannot use string offset as an array
[英]Fatal error: Cannot use string offset as an array - riot api curl/json/php
我对问题感到困惑,我很难解释自己。 我的这段代码通常可以很好地工作,但是更改为嵌套信息后,结果始终会导致Fatal error: Cannot use string offset as an array
。 即使我将所有内容恢复为旧状态,它也始终告诉我致命错误。 我正在使用RIOT API(传奇联盟)。
<?php
ini_set("display_errors", "1"); error_reporting(E_ALL);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://euw.api.pvp.net/api/lol/euw/v2.5/league/challenger?type=RANKED_SOLO_5x5&api_key=key');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response, true);
foreach($json as $elem)
{
echo $elem[0]['entries'][0]['playerOrTeamName'];
// echo $elem[0]['entries'][0]['miniSeries'][0]['wins'];
// echo $elem[0]['entries'][0]['miniSeries'][0]['losses'];
}
?>
您尚未正确探索阵列。
foreach ($json['entries'] as $entry)
{
echo $entry['playerOrTeamName'] . ' wins:' . $entry['wins'] . "<br/>";
}
而且,您的阵列和miniSeries不包含损耗。
请进一步彻底探索您的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.