Android JSONObject(Map copyFrom)构造函数在Genymotion和其他仿真器之间的工作结果不同
测试代码片段如下所示Android JSONObject(Map copyFrom)构造函数在Genymotion和其他仿真器之间的工作结果不同,android,genymotion,Android,Genymotion,测试代码片段如下所示 Map<String, Object> jsonMap = new HashMap<String, Object>(); ArrayList<Long> list = new ArrayList<Long>(); list.add(1L); list.add(2L); jsonMap.put("list", list); JSONObject json = new JSONObj
Map<String, Object> jsonMap = new HashMap<String, Object>();
ArrayList<Long> list = new ArrayList<Long>();
list.add(1L);
list.add(2L);
jsonMap.put("list", list);
JSONObject json = new JSONObject(jsonMap);
JSONArray ja = new JSONArray(list);
try {
json.put("JSONArray", ja);
} catch (JSONException e) {
e.printStackTrace();
}
if (json != null) {
System.out.println(json.toString());
return;
}
使用ADT emulator或我的nexus 4手机
{"JSONArray":[1,2],"list":[1,2]}
发生了什么?我终于在4.1.1 Genymotion设备上重现了您的问题,但也在4.1.1真实物理设备上重现了您的问题,如下图所示:(运行Cynogen的三星galaxy s2) 因此,我将这种行为称为GenyMoon特性 您将在4.1.2 ADT模拟器上看到相同的行为
您可能正在体验Android版本之间的差异。为了安全起见,你必须处理好这两个案子。这不符合我的习惯。你在试哪个genymotion版本和android版本?我用另一种方法来避免这个问题,谢谢你。但我对不同的实现很感兴趣。我读了这个类的android源代码,但不知道。你能帮我指出一下吗
{"JSONArray":[1,2],"list":[1,2]}