Json 做為一種輕量級的數(shù)據(jù)交換格式,開始受到親睞,有與 XML 搶地盤的風頭。而讓人高興的是,php也把 json 序列化數(shù)據(jù)的功能內(nèi)置成函數(shù)了,這讓想使用json的 PHPCoder 備感方便。
美中不足的是,json_encode / json_decode 系列函數(shù)只有在 php5.2 以上才有。這讓立志開發(fā)兼容性強的PHP系統(tǒng)的coder很頭痛。
幸好,已經(jīng)有人把 json 的方法封裝成 php4.x 系列甚至更低的版本都可以執(zhí)行的類了。這里要先謝謝先驅(qū)了。讓我們可以踩在巨人的肩膀上走向成功。
這里了解更多:http://code.VeVb.com/php/JSON-class.html
使用方法:
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);
}
?>
|
新聞熱點
疑難解答