Use JSON in PHP 4 or PHP 5.1.x :
Here i will explain how to use JSON (json_encode() , json_decode()) in versions of PHP earlier than 5.2. Add the following custom function to use (json_encode() , json_decode()) this functions in php. IF u don't have this JSON PEAR Package You can download in HERE
1. for json_encode() :
if (!function_exists('json_encode')) {
function json_encode($content) {
require_once 'classes/JSON.php';
$json = new Services_JSON;
return $json->encode($content);
}
}
2. for json_decode() :
if (!function_exists('json_decode')) {
function json_decode($content, $assoc=false) {
require_once 'classes/JSON.php';
if ($assoc) {
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
}
else {
$json = new Services_JSON;
}
return $json->decode($content);
}
}
Now you can work with JSON, even when you eventually upgrade to PHP 5.2.
The JSON PEAR Package download page link is given below :
>>> Download the Services_JSON PEAR package
0 comments:
Post a Comment