PHP - JSON

php

http://www.sitepoint.com/use-jsonserializable-interface

How to use JSON on RedHat 5?

If you need JSON and are stuck on Red Hat 5 (which has PHP 5 but without JSON), you can:

pear install pecl/json

See http://benlancaster.wordpress.com/2009/09/15/installing-php-json-centos-rhel-5/

How to deal with "Cannot use object of type stdClass as array" error?

If you are experiencing the "Cannot use object of type stdClass as array" error, PHP documentation recommend that you specify the second parameter as true:

$json_str = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
$json = json_decode($json_str, true)

But if you are stuck on Red Hat 5 and had to install the above JSON library, you may have to use type casting:

$json_str = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
$json = (array) json_decode($json_str)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License