avatar
Fix PHP json_decode

Guest 253 25th Jan, 2019

                                           
                         <?php
$json_string = 'http://www.domain.com/jsondata.json';

$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata);
print_r($obj['Result']);
?>
Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\temp\asklaila.php on line 6

=========Fix===========

As per the documentation, you need to specify if you want an associative array instead of an object from json_decode, this would be the code:

json_decode($jsondata, true);
                      
                                       
To share this paste, please copy this url and send to your friends.
RAW Paste Data