PHP JSON_decode 返回为 null 问题

解决方案

<?php
$html=file_get_contents("http://pad.skyozora.com/data/pets.json");
$html=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $html);
var_dump(json_decode($html, true));
var_dump(json_last_error());
?>

问题原因

因为 API 是 aspx、ashx, 可能会有 BOM(回传有中文), 于是使用此篇 "PHP 判断/移除 BOM(UTF-8)" 的 方法 先將 $json_data 过滤一次, 再来解析就行了

转自:https://learnku.com/articles/21030

猜你喜欢

转载自blog.csdn.net/amberom/article/details/86699278