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 in C:\\w
json_decode
support second argument, when it set to TRUE
it will return an Array
instead of stdClass Object
. Check the Manual page of json_decode
function to see all the supported arguments and its details.
For example try this:
$json_string = 'http://www.example.com/jsondata.json';
$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata, TRUE); // Set second argument as TRUE
print_r($obj['Result']); // Now this will works!