2 sachinks SachinKS 于 2013.08.21 16:44 提问

getLong和getString获取的值不同

代码如下:

 JSONObject contentObject = new JSONObject(content);
 JSONObject params = contentObject.getJSONObject("response_params");
 Log.d("onTest", "channel_id:" + params.getString("channel_id"));
 Log.d("onTest", "channel_id:" + params.getLong("channel_id"));

日志打印:

  08-21 12:46:21.470: DEBUG/onTest(25228): onMessage: content : {"response_params":{"appid":"1071410","channel_id":"3537275240990320342","user_id":"714893193627619861"},"request_id":1293438498}
   08-21 12:46:21.480: DEBUG/onTest(25228): channel_id:3537275240990320342
   08-21 12:46:21.480: DEBUG/onTest(25228): channel_id:3537275240990320128

为什么getLong 值是3537275240990320128
而String 值是3537275240990320342

1个回答

lanhailvcao
lanhailvcao   2013.08.21 17:24
已采纳

说明文档里是这样写的:

public long getLong (String name)

Returns the value mapped by name if it exists and is a long or can be coerced to a long. Note that JSON represents numbers as doubles, so this is lossy; use strings to transfer numbers via JSON.

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!