What is the best way to combine (merge) 2 JSONObjects?

后端 未结 5 1390
梦毁少年i
梦毁少年i 2021-02-19 02:14

What is the best way to combine (merge) two JSONObjects?

JSONObject o1 = {
    \"one\": \"1\",
    \"two\": \"2\",
    \"three\": \"3\"
}
JSONObject         


        
5条回答
  •  终归单人心
    2021-02-19 03:20

    How about this:

                Iterator iterator = json2.keys();
                while(iterator.hasNext()){
                    String key = iterator.next().toString();
                    json1.put(key,map.optJSONObject(key));
                }
    

提交回复
热议问题