Cannot use object of type stdClass as array?

Dail picture Dail · Jul 25, 2011 · Viewed 697.5k times · Source

I get a strange error using json_decode(). It decode correctly the data (I saw it using print_r), but when I try to access to info inside the array I get:

Fatal error: Cannot use object of type stdClass as array in
C:\Users\Dail\software\abs.php on line 108

I only tried to do: $result['context'] where $result has the data returned by json_decode()

How can I read values inside this array?

Answer

Jon picture Jon · Jul 25, 2011

Use the second parameter of json_decode to make it return an array:

$result = json_decode($data, true);