json_解码大数

问题描述 投票:0回答:3

我在解码 json 字符串时遇到问题

我的 PHP 版本是 5.4.4-7,我的操作系统是 Debian amd64。

JSON 字符串是:

{"status":"success","account":{"buy_title":"KGP ID","birthday":0,"sex":0,"phone_number":"","avatar":"http:\/\/\/default\/avatar_default.png","password":"","virtual_id":"1348718752795","point":0,"quota":2,"level":1,"remain":3413838437,"token":"9702040ea11e2b87d005056b771ea","email":"[email protected]","buy_link":"http:\/\/id.kgp.vn","fullname":""}}*

我想得到 remain = 3413838437 和 virtual_id = 1348718752795 但是当我得到

$result = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

$result['account']['remain']
它返回 2147483647 和
$result['account']['virtual_id]
也返回 2147483647。我不知道为什么我已经搜索并找到了https://groups.google.com/forum/?fromgroups=#!topic/php-json/c-zOACBlCPs但是链接补丁已经死了

如何解决?

php json biginteger
3个回答
3
投票

ini_set('精度', 20);

或者在 php.ini 中搜索精度并将精度设置为 20.


2
投票

这对我来说很好用:

php > print_r(json_decode($json, true));
Array
(
    [status] => success
    [account] => Array
        (
            [buy_title] => KGP ID
            [birthday] => 0
            [sex] => 0
            [phone_number] => 
            [avatar] => http:///default/avatar_default.png
            [password] => 
            [virtual_id] => 1348718752795
            [point] => 0
            [quota] => 2
            [level] => 1
            [remain] => 3413838437
            [token] => 9702040ea11e2b87d005056b771ea
            [email] => [email protected]
            [buy_link] => http://id.kgp.vn
            [fullname] => 
        )

)

这是在 64 位 PHP 上,您也在运行它,因为您的 PHP_INT_SIZE 是 8.


0
投票

这是因为在数据库中我设置这个字段是INT。我刚刚修改为 bigint,它工作正常!

© www.soinside.com 2019 - 2024. All rights reserved.