<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.4.7</version>
</dependency>
{
"name": "Alice",
"age": 25
}
public class Person {
private String name;
private int age;
// ...
}
public class Main {
public static void main(String[] args) {
Person person = new Person();
person.setName("Alice");
person.setAge(25);
String json = JSON.toJSONString(person);
System.out.println(json);
}
}
{"name":"Alice","age":25}
public class Main {
public static void main(String[] args) {
String json = "{\"name\":\"Alice\",\"age\":25}";
Person person = JSON.parseObject(json, Person.class);
System.out.println(person.getName());
System.out.println(person.getAge());
}
}
Alice
25