首页 > 代码库 > java 生成json对象

java 生成json对象

1.

JSONObject jsonObject = new JSONObject();jsonObject.put("a", "1");jsonObject.put("b", "2");jsonObject.put("c", "3");System.out.println(jsonObject);
{"a":"1","b":"2","c":"3"}

2.

Map<String, String> map = new HashMap<String, String>();map.put("a","1");map.put("b","2");map.put("c","3");System.out.println(JSONObject.fromObject(map));
{"b":"2","c":"3","a":"1"}

 

java 生成json对象