程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> json-getLong和getString獲取的值不同

json-getLong和getString獲取的值不同

編輯:編程綜合問答
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

最佳回答:


說明文檔裡是這樣寫的:

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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved