Java中JSON和对象的相互转换
Jackson
jar包下载地址:https://repo1.maven.org/maven2/com/fasterxml/jackson/core/
Person p = new Person("aaa", 18);
// 创建ObjectMapper对象om
ObjectMapper om = new ObjectMapper();
// 将对象转为JSON
String s = om.writeValueAsString(p);
System.out.println(s);
// 将JSON转为对象
Person newP = om.readValue(s, Person.class);
System.out.println(newP);