【发布时间】:2014-09-25 23:43:24
【问题描述】:
我遇到了一些我自己很难解释的问题。我的这段代码通常工作得很好,但是在我更改为嵌套信息后,结果总是导致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'];
}
?>
【问题讨论】:
-
$elem[0]或$elem[0]['entries'][0]是一个字符串。 -
我不明白为什么 [0] 也必须放在
entries之后。您能否解释一下为什么必须添加它才能以字符串形式结算?编辑-我很困惑,我现在似乎明白了。但是当我添加 echo $elem[0]['entries'][0]['playerOrTeamName'][0]; 时仍然无法正常工作 -
只输出
$json变量和var_dump。 -
检查 20ff.net 我现在已禁用所有回声。 var_dump($json) 现在处于活动状态。该代码在错误弹出之前有效,但现在不再有效。我不知道为什么。
-
你想达到什么目的?