百度 | 神马 | 搜狗 | 技术文档 | 学习资料分享 - 记录帝国CMS及运维技术的点点滴滴
你的位置:首页 > 实用IT技术 » 正文

【Wordpress相关】PHP json_decode 无法解析,那就试试 Services_JSON

发布时间:2020-09-17

作品分类:Wordpress相关  解析  那就  函数  那就  解析  试试  PHP  json_decode

PHP json_decode 无法解析,那就试试 Services_JSON,

PHP 的 json_decode 函数不知道是有bug,还是考虑太少,常常会发生解析不出数据的情况,使用 json_last_error_msg() 函数大部分情况下可以获得下面的错误:

Control character error, possibly incorrectly encoded

但是 Google 了一圈,都没有办法去修正这个错误,后面咨询了,他说:“json_decode经常会有东西解不出来的,应该用一个叫Sevice_JSON的类去解析,这个比较全能,帮你把特殊字符都处理好了”,试了下果然可以。

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>

到这里直接下载 ,然后直接使用:

<?php
include 'JSON.php';
$json = new Services_JSON();
$data = $json->decode($str);
?>

既可以了,如果想和 json_decode 的第二个参数一样,可以解析返回的数据为数组,那就要在 new Services_JSON 的时候加上这个参数 SERVICES_JSON_LOOSE_TYPE

<?php
include 'JSON.php';
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$data = $json->decode($str);
?>

本站推荐使用的主机:,国外主机建议使用

Top