JSONArray array2 = new JSONArray(); array2.put(false); String path = "//storage/emulated/0/spap/image/1560929771359_bridge.jpg"; JSONObject obj2 = new JSONObject(); try { obj2.put("file",path); obj2.put("size",1000); array2.put(obj2); }catch (Exception e) { e.printStackTrace(); } Log.e("fxz","====params:" + array2.toString());
如果org.json.JsonArray执行上述代码,结果是:
/fxz: ====params:[false,{"file":"\/\/storage\/emulated\/0\/spap\/image\/1560929771359_bridge.jpg","size":1000}]
当执行array2.put(obj2)的时候,obj2中的值被特殊处理?
将生成的字符串android端传给js,报:Uncaught SyntaxError: missing ) after argument list
JsonArray ja = new JsonArray(); String file = "/storage/emulated/0/spap/image/1560929771359_bridge.jpg"; try { ja.add(false); JsonObject o = new JsonObject(); o.addProperty("path",file); o.addProperty("size",1000L); ja.add(o); Log.e("fxz","###->" + ja.toString()); }catch (Exception e) { e.printStackTrace(); }
如果使用com.google.gson.执行上述代码,结果是:
/fxz: ###->[false,{"path":"/storage/emulated/0/spap/image/1560929771359_bridge.jpg","size":1000}]
使用此方法没上述问题。
check WHY?
期待大牛的指导。。。。。