PHP中json_decode的整型溢出的解决⽅法1.正则表达式
$array = array(
"id1" => 2147483647,
"id2" => 2147483648
);
phpjson格式化输出$json = json_encode($array);
$json = preg_replace('/("id\d":)(\d{9,})/i', '${1}"${2}"', $json);
$out = json_decode($json, true);
var_dump($out);
2.php5.3以后⽣效
$json = '12345678901234567890';
var_dump(json_decode($json));
var_dump(json_decode($json, false, 512, JSON_BIGINT_AS_STRING));
3.number_format函数
$obj='{"order_id":213477815351175,"buyer":100001169269154}';
$obj=$this->json_decode($obj,TRUE);
foreach ($obj as $key=>$val){
$obj[$key]=number_format($val,0,'','');
}
print_r($obj);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。