分享一个好用的 JSON 解析库
原创 52cxy 09-14 17:33 阅读数:567

在 PHP 中, json_encode、json_decode 常用来对 json 库进行处理,但是在使用 json_decode 时经常出现无法正常解析的情况,此时可以使用替换的方式来处理,如 Services_JSON 库。

该库的使用方法也很简单:

$str  = '{"content": "{\\\"name\" : \"张三\"}"}';

//使用 json_decode 解析会报错,错误码为4,返回为空
$data = json_decode($str);

//使用 Services_JSON 解析则正常
$json = new Services_JSON();
$data = $json->decode($str);


共0条评论
我要评论