Home > Article > Backend Development > Tutorial on using json_encode_PHP in PHP
As a lightweight data exchange format, Json has begun to gain popularity and competes with XML for the limelight. What is gratifying is that PHP has also built-in the function of json serialized data as a function, which makes PHPCoder who want to use json very convenient.
The only drawback is that the json_encode / json_decode series of functions are only available in php5.2 and above. This gives coders who are determined to develop a highly compatible PHP system a headache.
Fortunately, someone has already encapsulated the json method into a class that can be executed by the php4.x series or even lower versions. I would like to thank the pioneer in advance. Let us step on the shoulders of giants and achieve success.
Learn more here: http://code.itlearner.com/php/JSON-class.html
How to use:
if( function_exists("json_encode") )
{
return json_encode($phparr);
}
else
{
require_once ROOT."include/json.class.php";
$json = new Services_JSON;
return $json->encode($phparr);
}