echo '<pre>';
$test = array('id'=>'181601920729896967', 'name'=>'test');
echo json_encode($test); echo '<br>';
$json = '{"id":181601920729896967,"name":"test"}';
$data = json_decode($json, true);
print_r($data);
$str = number_format($data['id'], 0, '', '');
print_r($str);
$newdata = json_decode($json, true , 512 , JSON_BIGINT_AS_STRING);
echo '<br>-------------<br>';
print_r($newdata);
exit;
执行结果截图如下:
第一:json_decode在解析bigint时需要特殊处理一下:可查看手册,json_decode有第4个参数,就是用来控制解析bigint的,如上示例中使用了第4个参数就正常。
optionsBitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats)
第二:科学计数法转换成正常的数值的方法:
$number = number_format($number, 0, '', '');