致命错误:无法将字符串偏移量用作数组-riot-api-curl/json.php


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/>";
     }

此外,您的阵列不包含loss和miniSeries。

请进一步深入研究您的数据。