I am stuck using a pre 5.2 release of PHP (v 5.1.6), and therefore don't have access to the handy functions like json_decode()
To complicate matters, I also don't have server privileges to install any extensions.
It would be really nice to simply include a class definition that i can use to create objects (or even a complex array) from a string of json data.
Does anyone know of a lightweight and reliable class definition that will work for me?
(I don't really feel like re-inventing the wheel here.)
Thanks in Advance!
You can download the pear JSON library directly and include the script in your app. Check out this link: http://pear.php.net/package/Services_JSON/download
You can use Services_JSON on PEAR, you'll use it like this:
if ( !function_exists('json_decode') ){
function json_decode($content, $assoc=false){
include_once('JSON.php');
if ( $assoc ){
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
} else {
$json = new Services_JSON;
}
return $json->decode($content);
}
function json_encode($content){
include_once('JSON.php');
$json = new Services_JSON;
return $json->encode($content);
}
}
Check out Zend_Json, it seems OK, but I don't know the minimum php version required.