title: Trying to get property of non-object json in php
body: <p>I am trying to get this code to work but I keep getting this error :</p>
  
  <blockquote>
    <p>Trying to get property of non-object..</p>
  </blockquote>
  
  <p>I've validated my <code>json</code> object, but still no luck. I searched for the problem but didn't find any solution. First part of my code which creates the <code>JSON</code> and print it:</p>
  
  <pre><code>$response['team']['tid'] = $teamData['tid'];
  $response['team']['name'] = $teamData['name'];
  $response['team']['wins'] = $teamData['wins'];
  $response['team']['group'] = $teamData['tgroup'];
  $otherTeamNames = $db-&gt;query("SELECT name from teams where tgroup= '$teamData[4]'");
  
  while($values = $otherTeamNames-&gt;fetch(PDO::FETCH_ASSOC) ){
      if($values['name'] != $teamData['name'])
      $response['team']['otherteam'][] = $values;
  
  }
  $response['success'] = 1;
  echo json_encode($response);
  </code></pre>
  
  <p>the second part which will decode the JSON </p>
  
  <pre><code>$json = file_get_contents('http://localhost/pract/getSingleTeamById.php', false, $context);
  
  $teamInformation = json_decode($json);
  $success = $teamInformation-&gt;{"success"};
  </code></pre>
  
  <p>The output of <code>$json</code> before decoding:</p>
  
  <pre><code>{"team":{"tid":"2","name":"Italy","wins":"4","group":"D","otherteam":[{"name":"Uruguay"},{"name":"England"}]},"success":1}
  </code></pre>
  
  <p>Any help would be appreciated.</p>