PHP JSON返回null或空字符解决办法
原因分析
其它的json_decode($str)返回NULL的一些原因:
1.$str只能UTF-8编码
2.元素最后不能有逗号(与php的array不同)
3.元素不能使用单引号
4.元素值中间不能有空格和\n,必须替换
在用PHP JSON处理符合标准的GBK编码内容时会返回null,将内容从GBK转换为UTF8再处理正常:
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8836')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy8836>
$jsonp = mb_convert_encoding($jsonp, "gbk", "utf-8");
//或
$jsonp = iconv('gbk','utf-8',$jsonp)
您可能感兴趣的文章:
PHP JSON返回null或空字符解决办法
淘宝API返回的json数据无法用json_decode的问题
Jquery ajax不能解析json对象,报Invalid JSON错误的原因和解决方法
MySQL 5.7的JSON数据类型详解介绍
解决json_encode 函数中文被编码成 null的办法
jquery获取下拉列表的值为null的解决方法
php中json_encode gbk/gb2312中文乱码问题
php如何将json文本转换成数组
PHP怎么把JSON转换成数组?
php解析JSON中文乱码问题的解决方法