开发者社区> 问答> 正文

json中一个对象里面有两个数组为什么数组最后是null?

话不多说直接上代码
screenshot
screenshot
screenshot
screenshot
screenshotscreenshotscreenshot
然后一运行报错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" }
      }
    ]
  }
}

展开
收起
杨冬芳 2016-07-07 17:33:23 2550 0
1 条回答
写回答
取消 提交回答
  • IT从业
    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/

    2019-07-17 19:53:02
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载