PHP json_decode返回null解析失败原因

来源:互联网 发布:ubuntu服务器重装系统 编辑:程序博客网 时间:2024/04/30 10:07
<?php    $result = json_decode(trim($contents,chr(239).chr(187).chr(191)),true);    print_r($result );?>
son_decode函数有两个参数json_decode有两个参数,第一个是待解析的字符串,第二个是是否解析为Array


json_decode要求的字符串比较严格:
(1)使用UTF-8编码
(2)不能在最后元素有逗号
(3)不能使用单引号
(4)不能有\r,\t,如果有请替换


所以问题来了,不小心在返回的json字符串中返回了BOM头的不可见字符,某些编辑器默认会加上BOM头
0 0
原创粉丝点击