话不多说直接上代码
然后一运行报错Exception in thread "main" java.lang.NullPointerException at per.swwfourteen.fourteen.JsonRoot.main(JsonRoot.java:12)调试发现在运行时Root_List root=JSONObject.parseObject(ReadRoot("D:"+File.separator+"1.json"),Root_List.class);其中student和teacher的值都是null,很是不
{
"Root": {
"student": [
{
"id": "001",
"name": "student1",
"password": "123",
"age": "20"
},
{
"id": "002",
"name": "student2",
"password": "456",
"age": "21"
},
{
"id": "003",
"name": "student3",
"password": "123",
"age": "21"
}
],
"teacher": [
{
"id": "001",
"name": "teacher1",
"password": "123",
"age": "20",
"car": { "num": "098" }
},
{
"id": "002",
"name": "teacher2",
"password": "123",
"age": "20",
"car": { "num": "098" }
}
]
}
}
package ;
import java.util.List;
public class Root {
private List student ;
private List teacher ;
public void setStudent(List student){
this.student = student;
}
public List getStudent(){
return this.student;
}
public void setTeacher(List teacher){
this.teacher = teacher;
}
public List getTeacher(){
return this.teacher;
}
}
你要自己去试试,capy的时候,集合类型会消失http://www.bejson.com/json2javapojo/
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。