php的json_decode函数返回null的问题
可以使用使用json_last_error()函数获取到的返回值来帮助我们判断出问题的原因。
其中如果提示错误JSON_ERROR_SYNTAX(Syntax error),表示json串格式错误。
可以通过以下几个方式排错:
1. json字符串必须以双引号包含
<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('copy5244')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5244>$output = str_replace("'", '"', $output);
2. json字符串必须是utf8编码
$output = iconv('gbk', 'utf8', $output);
3.不能有多余的逗号 如:[1,2,]
用正则替换掉,preg_replace('/,\s*([\]}])/m', '$1', $output)
您可能感兴趣的文章:
淘宝API返回的json数据无法用json_decode的问题
php的json_decode函数返回null的问题
php如何将json文本转换成数组
json_decode返回null空问题解决方法
php中GBK/GB2312页面使用json_decode()中文丢失了解决方法
php中怎么把json转成对象数组
PHP怎么把JSON转换成数组?
php中json_decode函数要注意的问题
PHP Fatal error: Cannot use object of type stdClass as array in错误
php中如何使用json_decode()和json_encode()?