I am trying to decode a JSON string into an array but i get the following error.
Fatal error: Cannot use object of type stdClass as array
Here is the code:
$json_string = 'http://www.example.com/jsondata.json';
$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata);
print_r($obj['Result']);
As per the documentation, you need to specify
trueas the second argument if you want an associative array instead of an object fromjson_decode. This would be the code:If you want
integerkeys instead of whatever the property names are:However, with your current decode you just access it as an object: