如果要使用两个键Object1和Object2创建新对象,则可以执行以下操作:
JSonObject Obj1 = (JSONObject) jso1.get("Object1");JSonObject Obj2 = (JSONObject) jso2.get("Object2");JSonObject combined = new JSonObject();combined.put("Object1", Obj1);combined.put("Object2", Obj2);如果要合并它们,例如顶级对象有5个键(Stringkey1,ArrayKey,StringKey2,StringKey3,StringKey4),我认为您必须手动执行此操作:
JSonObject merged = new JSonObject(Obj1, JSONObject.getNames(Obj1));for(String key : JSONObject.getNames(Obj2)){ merged.put(key, Obj2.get(key));}如果JSONObject实现Map,并支持putAll,这会容易得多。



