在调试一个接口的时候遇到一个难题,PHP curl到传来的JSON数据后,通过json_decode却无法将获得的这个json转换成PHP数组;
经过一番查询才发现,对方生成的JSON不规范,带有BOM格式
curl得到的JSON数据中带有bom格式的必须先去除BOM格式才能通过json_decode转换成数组
有些返回数据直接:
print_r(json_decode($data,true));
就可以转换。
if(preg_match('/^\xEF\xBB\xBF/',$output)) { $output = substr($output,3); } $info = json_decode(trim($output),true);