json字符串 转 map/array
map: public static JSONObject parseObject(String text)
arary: public static JSONArray parseArray(String text)
String arrStr = "[{"addr":"Pudong Shanghai","age":18,"name":"jack"},{"addr":"JingAn Shanghai","age":18,"name":"rose"}]";
String objStr = "{"addr":"Pudong Shanghai","age":18,"name":"jack"}";
JSONObject jsonObject = JSON.parseObject(objStr);
JSONArray jsonArr = JSON.parseArray(arrStr);
字符串 转 对象
String jsonStr = "{"addr":"Pudong Shanghai","age":18,"name":"jack"}";
Person per = JSON.parseObject(jsonStr, Person.class);
System.out.println(per);
object、数组、map 转 json字符串
public static String toJSONString(Object object)
Person jack = new Person("jack", 18, "Pudong Shanghai");
String str = JSON.toJSONString(jack);