import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* @program: jdk17Test
* @author: quxiao
* @create: 2023-12-21 15:56
**/
public class T3 {
static class quiao {
@Override
public String toString() {
return "quiao{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public quiao(String name, int age) {
this.name = name;
this.age = age;
}
}
public static void main(String[] args) {
List<quiao> list = new ArrayList<>();
list.add(new quiao("gagas", 18));
list.add(new quiao("gagas", 18));
list.add(new quiao("gagas", 18));
list.add(new quiao("gagas", 18));
String s = JSONObject.toJSONString(list);
List<quiao> quiaos = JSONObject.parseArray(s, quiao.class);
System.out.println(quiaos);
}
static void t1() {
List<String> list = new ArrayList<>();
list.add("123");
list.add("456");
String toJSONString = JSONObject.toJSONString(list);
System.out.println(toJSONString);
List<String> list1 = JSONObject.parseArray(toJSONString, String.class);
System.out.println(list1);
}
}
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>2.0.25</version> </dependency>
还是学springmvc的时候,用了一次这个 ,转眼一年多就过去了,工作突然用到了,记个笔记吧