在android上创建类并解析JSON数组

时间:2016-11-05 14:17:45

标签: android json parsing

我有以下JSON输出示例:

[   {     " id":" 1",     " first_name":" AAA",     "姓氏":" BBB",     "课程":[       {         " name":" CCC",         "成绩":" 90"       },       {         " name":" CCC",         "成绩":" 90"       },       {        " name":" CCC",         "成绩":" 90"       }     ]   },   {     " id":" 2",     " first_name":" AAA",     "姓氏":" BBB",     "课程":[]   },   {     " id":" 3",     " first_name":" AAA",     "姓氏":" BBB",     "课程":[       {         " name":" CCC",         "成绩":" 90"       },       {         " name":" CCC",         "成绩":" 90"       }     ]   },   {     " id":" 3",     " first_name":" AAA",     "姓氏":" BBB",     "课程":[       {         " name":" CCC",         "成绩":" 90"       },       {         " name":" CCC",         "成绩":" 90"       },       {         " name":" CCC",         "成绩":" 90"       },       {         " name":" CCC",         "成绩":" 90"       },       {         " name":" CCC",         "成绩":" 90"       }     ]   } ]

我需要帮助创建类并解析这个JSON。

提前感谢。

1 个答案:

答案 0 :(得分:0)

public class Course {
    private String name;
    private String grade;
}

public class Person {
    private String id;
    private String firstName;
    private String lastName;
    private List<Course> courses = new ArrayList<Course>();
}

这个网站非常有用 - http://www.jsonschema2pojo.org/