解码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":"ngokhat@gmail.com","buy_link":"http:\/\/id.kgp.vn","fullname":""}}*
我想保持= 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但链接补丁已经死亡
如何解决这个问题?
答案 0 :(得分:3)
ini_set('precision',20);
或在php.ini中搜索精度并将精度放在20。
答案 1 :(得分: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] => ngokhat@gmail.com
[buy_link] => http://id.kgp.vn
[fullname] =>
)
)
这是在64位PHP上运行的,因为你的PHP_INT_SIZE是8。
答案 2 :(得分:0)
很抱歉,因为在数据库中我设置此字段是INT:D 我刚修改为bigint,它工作正常! 感谢您的支持!