org.json.JSONObject.getLong给出了不精确的结果 [英] org.json.JSONObject.getLong gives imprecise result

查看:506
本文介绍了org.json.JSONObject.getLong给出了不精确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In android,我们可以看到附图,
我从服务器收到的json是id = -705156352446547 2446
但是代码 jsonObject。 getLong(id)给出-705156352446547 2512

In android, as we can see attached figure, the json that I received from server is "id=-7051563524465472446" but the code jsonObject.getLong("id") gives -7051563524465472512.

我可以看到每个 getLong 转换在最后4位数内有不精确的结果(或丢失精度?)。
有什么我错过的吗?

I can see every getLong conversion has imprecise result(or lose precision?) in last 4 digits. Is there anything that I missed?

我的设置:java 1.6.0_41,Android 4.1.2,IntelliJ 12 IDE。

My settings: java 1.6.0_41, Android 4.1.2, IntelliJ 12 IDE.

推荐答案

Long.parseLong(jsonObject.getString(id))给出精确的结果。

这篇关于org.json.JSONObject.getLong给出了不精确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆