json_decode 将大数字字符串解码为整数
json_decode decodes large numeric string as integer
我有类似下面的代码:
<?php
$str = "76017060710034014696970658200876993546";
if(json_decode($str) !== null && json_decode($str) !== false){
var_dump(json_decode($str));
}
?>
结果如下:
int(9223372036854775807)
当然,这不是 json 字符串,我希望 json_decode 到 return 为 null 或 false,如 manual:
Return Values
Returns the value encoded in json in appropriate PHP type. Values
true, false and null are returned as TRUE, FALSE and NULL
respectively. NULL is returned if the json cannot be decoded or if the
encoded data is deeper than the recursion limit.
这怎么可能?这是一个错误还是我遗漏了什么?
您缺少一个选项 JSON_BIGINT_AS_STRING,顺便说一句,字符串是有效的 json。尝试以下操作:
var_dump(json_decode($str, false, 512, JSON_BIGINT_AS_STRING));
我有类似下面的代码:
<?php
$str = "76017060710034014696970658200876993546";
if(json_decode($str) !== null && json_decode($str) !== false){
var_dump(json_decode($str));
}
?>
结果如下:
int(9223372036854775807)
当然,这不是 json 字符串,我希望 json_decode 到 return 为 null 或 false,如 manual:
Return Values
Returns the value encoded in json in appropriate PHP type. Values true, false and null are returned as TRUE, FALSE and NULL respectively. NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.
这怎么可能?这是一个错误还是我遗漏了什么?
您缺少一个选项 JSON_BIGINT_AS_STRING,顺便说一句,字符串是有效的 json。尝试以下操作:
var_dump(json_decode($str, false, 512, JSON_BIGINT_AS_STRING));