php json_encode方法 报错:Inf and NaN cannot be JSON encoded

      发布在:后端技术      评论:0 条评论

json_encode 返回false
var_dump(json_encode($array));

通过json_last_error_msg查看报错原因
echo json_last_error_msg();
Inf and NaN cannot be JSON encoded

原因是$array里面包含了NAN 和INF 这些导致的

解决方案如下:

echo  json_encode(unserialize(str_replace(array('NAN;','INF;'),'0;',serialize($infos))));

摘抄自https://www.codeleading.com/article/54555038767/

相关文章
热门推荐