這是我的最後一個問題的延續: how to keep data stored into a hashtable - java錯誤值從JSONObject的未來 - java的
這裏是JSON:
{"DeviceID":"35181805087546548","TotalCount":"0","Timestamp":"2013-03-05 14:30:15"}
這裏是我的哈希表的聲明:
private static Hashtable<Integer,String> table = new Hashtable<Integer,String>();
private static AtomicInteger count = new AtomicInteger() ;
這裏是解析jsonobject的代碼:
JSONObject jsonObj;
try {
jsonObj = new JSONObject(string);
int id = jsonObj.optInt("DeviceID", count.addAndGet(1));
String name = jsonObj.toString();
table.put(id, name);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
即使JSON中的「DeviceID」發生變化,使用下面的代碼我的ID始終爲「2147483647」。 任何提示?
非常感謝
Sotirios,提出了答案,而不是一個問題 – 2013-03-05 20:46:04
+1以前看起來像一個有效的答案,現在也是如此。不需要粗魯。 – Gamb 2013-03-05 20:46:18
表達式非常重要,感謝您的更新。 – 2013-03-05 20:47:45