Showing posts with label json_decode. Show all posts
Showing posts with label json_decode. Show all posts

Tuesday, 16 February 2010

json_decode Fatal error: Cannot use object of type stdClass as array

You may receive the following error when encoding and decoding information using json in php

Fatal error: Cannot use object of type stdClass as array

When using json_decode, information is by default converted into an object. You need to use the function get_object_vars to convert the object into an array, like so;


$new_data = get_object_vars(json_decode($data));

print_r($new_data);

?>