java json 合并_JAVA中 fastjson两个JSONArray叠加,合并 ,方法 addAll

时间:2025-04-01 12:05:26

JAVA中 fastjson两个JSONArray叠加,合并用addAll()

package ;

import ;

import ;

/**

* 两个JSONArray叠加,合并 addAll()

* @author luolei

* @date 2019年2月14日

*/

public class TowJSONArrayMerge {

public static void main(String[] args) {

JSONArray jSONArray1 = new JSONArray();

JSONObject jsonObject1 = new JSONObject();

("name", "luo");

("sex", "男");

(jsonObject1);

JSONObject jsonObject2 = new JSONObject();

("name", "xing");

("sex", "女");

(jsonObject2);

("jSONArray1:" + jSONArray1);

JSONArray jSONArray2 = new JSONArray();

JSONObject jsonObject21 = new JSONObject();

("name", "luolei");

("sex", "男");

(jsonObject21);

JSONObject jsonObject22 = new JSONObject();

("name", "dxx");

("sex", "女");

(jsonObject22);

("jSONArray2:" + jSONArray2);

(jSONArray1);

("jSONArray2:" + jSONArray2);

//结果

/*jSONArray1:[{"name":"luo","sex":"男"},{"name":"xing","sex":"女"}]

jSONArray2:[{"name":"luolei","sex":"男"},{"name":"dxx","sex":"女"}]

jSONArray2:[{"name":"luolei","sex":"男"},{"name":"dxx","sex":"女"},{"name":"luo","sex":"男"},{"name":"xing","sex":"女"}]*/

}

}