java 组装复杂json

package com.dome.common.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JsonAssembly {

	public static void main(String[] args) {
		List> relist=new ArrayList<>();
		List> list=new ArrayList<>();
		Map map;
		
		for(int i=0;i<3;i++){
			map=new HashMap<>();
		    map.put("a1", "a"+i);
		    map.put("b1", "b"+i);
		    list.add(map);
		}
	    
	    map=new HashMap<>();
	    map.put("a", "a");
	    map.put("b", list);
	    relist.add(map);
	    
	    System.out.println(JSONArray.fromObject(relist));
		
	}
}

你可能感兴趣的:(java常用知识点)