1.创建json对象 1.1 创建JSONObject对象
使用map初始化json
@Test
public void test1()
{
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("name", "孙笑川");
map.put("age", 25);
map.put("height", 1.70);
map.put("major", new String[] { "理发", "挖掘机" });
map.put("hasGirlFriend", false);
map.put("car", null);
map.put("house", null);
//null作为value时,转换成json后不会保存
JSONObject json1 = new JSONObject(map);
System.out.println(json1.toString());
Map map2 = json1.toMap();
System.out.println(map2.toString());
}