public class JsonUtil { public static void main(String[] args) { JsonUtil j = new JsonUtil(); //j.bean2json(); j.list2json(); //j.map2json(); //j.json2bean(); }
public JSONArray arr2json() { boolean[] boolArray = new boolean[] { true, false, true }; JSONArray jsonArray = JSONArray.fromObject(boolArray); System.out.println(jsonArray);
// prints [true,false,true] return jsonArray; }
public JSONObject list2json() { List list = new ArrayList(); //list.add("first"); //list.add("second");
Map map1 = new HashMap(); map1.put("name", "json"); map1.put("sex", "男");
Map map2 = new HashMap(); map2.put("name", "json222"); map2.put("sex", "男222");