大家好,又見面了,我是你們的朋友全棧君。
List<T> list=JSONArray.parseArray("",T.class);
複制
其中T為要轉為的list其中的對象
public class Test {
public static void main(String[] args) {
String str = "[{\"name\":\"zym\"},{\"name\":\"sx\"}]";
List<Person> list = JSONArray.parseArray(str, Person.class);
System.out.println(list);
}
}
class Person{
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
複制
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIwIjNx8CX39CXy8CXycXZpZVZnFWbp9zZlBnaugjZ3UDZkBDMhZjYxMWZ2U2YjZDMlFGN4MmZjFTY3Y2Nvw1NzUzMyIDOtUGall3LcVmdhNXLwRHdo9CXt92YucWbpRWdvx2Yx5yazF2Lc9CX6MHc0RHaiojIsJye.jpeg)
釋出者:全棧程式員棧長,轉載請注明出處:https://javaforall.cn/146732.html原文連結:https://javaforall.cn