php 解析json失败,解析为空,json在线解析器可以解析,但是json_decode()解析失败

json在线解析器 是可以解析的

 

但是实际代码运行,不论是直接json_decode()还是去掉两边单引号都无法解析.

造成这种问题的源头就是bom头,返回的结果是带bom头的utf8格式的数据,因此只要去除bom头就好了,添加一个方法:

 

function clearBom($str){

   $bom chr(239).chr(187).chr(191);
   return str_replace($bom ,'',$str);    
}
$data = json_decode(clearBom($str),true);
var_dump($data);

 
 
 
posted @ 2020-08-07 09:56  拍片哥  阅读(455)  评论(0编辑  收藏  举报