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()处理

posted @ 2017-04-11 15:34  虽不能至,心向往之。  阅读(1151)  评论(0编辑  收藏  举报