php json 踩坑

189 阅读1分钟
json_encode 返回false
echo json_encode($array); 
通过json_last_error_msg查看报错原因 
echo json_last_error_msg(); 
Inf and NaN cannot be JSON encoded 
原因是$array里面包含了NAN 和INF 这些导致的 
解决方案如下: 
json_encode(unserialize(str_replace(array(‘NAN;’,’INF;’),’0;’,serialize($reply))));