当json内数值如3326550366031446016 这个数值这么大的时候
json解析后会返回float(3.3265503660314E+18)
在php5.4+后面都支持json_decode 的参数 JSON_BIGINT_AS_STRING
输出数据$output,
大数值会转成string类型
json_decode($output, true , 512 , JSON_BIGINT_AS_STRING);
知识点:
(PHP 5 >= 5.2.0, PHP 7, PECL json >= 1.2.0)
json_decode — 对 JSON 格式的字符串进行解码
说明 ¶
json_decode ( string $json
[, bool $assoc
= false [, int $depth
= 512 [, int $options
= 0 ]]] ) : mixed
接受一个 JSON 编码的字符串并且把它转换为 PHP 变量
参数 ¶
json
待解码的 json
string 格式的字符串。
这个函数仅能处理 UTF-8 编码的数据。
Note:
PHP implements a superset of JSON as specified in the original » RFC 7159.
assoc
当该参数为 TRUE
时,将返回 array 而非 object 。
depth
指定递归深度。
options
JSON解码的掩码选项。 现在有两个支持的选项。 第一个是JSON_BIGINT_AS_STRING
, 用于将大整数转为字符串而非默认的float类型。第二个是 JSON_OBJECT_AS_ARRAY
, 与将assoc
设置为 TRUE
有相同的效果。