猿问

php7 json_decode null

1、确认文件无BOM头

2、尝试了如下多种方式去除非法字符串,但是仍然输出NULL

        $some_string = htmlspecialchars_decode($some_string);

        $some_string = preg_replace("/\t/", " ", $some_string);
        $some_string = preg_replace("/\n/", ' ', $some_string);
        $some_string = str_replace("\n", ' ', $some_string);
        $some_string = str_replace ('\n','', $some_string);

3、json_last_error()输出4,Syntax error, malformed JSON

4、直接输出字符串,浏览器能够正常解析josn,如下截图

https://img.mukewang.com/5c8f386c0001ff3808000152.jpg

狐的传说
浏览 855回答 4
4回答

湖上湖

json_decode($jsonStr, true); 你有加 true 这个参数了吗?

泛舟湖上清波郎朗

信息比较少,不好判断,贴出$some_string来看看,或者说明下这个值是从哪里获取到的。。

慕妹3146593

$str=“json数据”; dump($json_decode($str)); echo $errorinfo=json_last_error(); 如果报错4则 htmlspecialchars_decode($str);处理下
随时随地看视频慕课网APP
我要回答