tp中对json_decode返回null的解决办法
Posted 虽不能至,心向往之。
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tp中对json_decode返回null的解决办法相关的知识,希望对你有一定的参考价值。
json_decode要求的字符串比较严格:
(1)使用UTF-8编码
(2)不能在最后元素有逗号
(3)不能使用单引号
(4)不能有\r,\t,如果有请替换
tp框架中的I函数默认对post的参数进行了htmlspecialchars过滤
‘DEFAULT_FILTER‘ => ‘htmlspecialchars‘, // 默认参数过滤方法 用于I函数...
string(23) "{"test":"url",‘attr‘:1}"
string(43) "{"test":"url",‘attr‘:1}"
json_decode是先进行htmlspecialchars_decode()处理
以上是关于tp中对json_decode返回null的解决办法的主要内容,如果未能解决你的问题,请参考以下文章
PHP 获取JSON json_decode返回NULL解决办法
json_decode 在 webservice 调用后返回 NULL