java 含有数组的字符串怎么转化为json对象
发布网友
发布时间:2022-04-25 14:43
我来回答
共1个回答
热心网友
时间:2023-10-09 16:16
1、需要json的相关jar包
2、设置json格式字符串:
String str="{\"student\":[{\"name\":\"leilei\",\"age\":23},{\"name\":\"leilei02\",\"age\":23}]}";
3、建立相应的类:
public class StudentList {
List<Student> student;
public List<Student> getStudent() {
return student;
}
public void setStudent(List<Student> student) {
this.student = student;
}
}
public class Student {
private String name;
private int age;
//private StudentClass studentClass;
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;
}
}