title: PHP Warning: Illegal string offset - json data
body: <p>I get the error  </p>
  
  <blockquote>
    <p>Warning: Illegal string offset '@name' in ...</p>
  </blockquote>
  
  <p>but only in 22 row based on this particular example.</p>
  
  <p>I looked for a solution, that this might be from taking a string as an array, but I don't get a clue how to deal with this. Here is the code:</p>
  
  <pre><code>$setlista="23e278a7";  
  
  $url = "http://api.setlist.fm/rest/0.1/setlist/".$setlista.".json";
  
    $json = file_get_contents($url);
    $obj = json_decode($json, true);
  
    $setlistByEvent = $obj['setlist']['sets']['set'];
  
    $countSongs = 1;
  
    for ($i = 0; $i &lt;= count($setlistByEvent) - 1; $i++) {
  
    echo "&lt;ul&gt;";
  
    if($i &gt; 0) {
      echo "Encore " . $setlistByEvent[$i]['@encore'] ;
    }
  
    foreach($setlistByEvent[$i]['song'] as $row) {
        echo "&lt;li&gt;";
        echo $countSongs . ". ";
        echo $row['@name'];
        echo "&lt;/li&gt;";
      $countSongs++;
    }
  
    echo "&lt;/ul&gt;"; 
  
    }  
  </code></pre>
  
  <p>The output is:</p>
  
  <blockquote>
    <ol>
    <li>This House Is Not for Sale</li>
    <li>Raise Your Hands</li>
    <li>Knockout</li>
    <li>You Give Love a Bad Name</li>
    <li>Born to Be My Baby</li>
    <li>Lost Highway</li>
    <li>We Weren't Born to Follow</li>
    <li>Lay Your Hands On Me</li>
    <li>In These Arms</li>
    <li>New Year's Day</li>
    <li>(You Want to) Make a Memory</li>
    <li>Bed of Roses</li>
    <li>It's My Life</li>
    <li>Someday I'll Be Saturday Night</li>
    <li>Wanted Dead or Alive</li>
    <li>I'll Sleep When I'm Dead</li>
    <li>Have a Nice Day</li>
    <li>Keep the Faith</li>
    <li>Bad Medicine
    Encore 1</li>
    <li>Always</li>
    <li>Livin' on a Prayer 
    Encore 2</li>
    <li>Warning: Illegal string offset '@name' in...</li>
    </ol>
  </blockquote>