如何解析json与android中的改造

时间:2016-10-15 13:10:02

标签: android json retrofit

请我需要你的帮助,我想在我的应用程序中解析以下json并在android中进行改造,但问题是我不知道如何创建我的模型类, 我想显示每个排名的标题,排名,名称,标题,差异和分数,

我的json:

    {
"channel": {},
"classification": [
            {
            "day": {
                "id": "3169",
                "accr": "J8",
                "type": "0",
                "title": "8ème journée",
                "start": "2016-10-08",
                "finish": "2016-10-09",
                "poolid": "36",
                "pool_name": null,
                "rankings": {
                        "1": {
                            "club": {},
                            "evolution": {},
                            "difference": "77"

                            },
                        "2": {
                            "club": {},
                            "evolution": {},
                            "difference": "47"

                            },
                        "3": {
                            "club": {},
                            "evolution": {},
                            "difference": "61"

                            }
                    }
                }
            }
        ]
}

my top14

{
"channel": {},
"classification": [
            {
            "day": {
                "id": "3169",
                "accr": "J8",
                "type": "0",
                "title": "8ème journée",
                "start": "2016-10-08",
                "finish": "2016-10-09",
                "poolid": "36",
                "pool_name": null,
                "rankings": {
                        "1": {
                            "club": {},
                            "evolution": {},
                            "difference": "77"

                            },
                        "2": {
                            "club": {},
                            "evolution": {},
                            "difference": "47"

                            },
                        "3": {
                            "club": {},
                            "evolution": {},
                            "difference": "61"

                            }
                    }
                }
            }
        ]
}

我的top14lst

public class Top14List {
    @SerializedName("classification")
    @Expose
    private ArrayList<Top> classification = new ArrayList<>();
    public ArrayList<Top> getClassification() {
        return classification;
    }
    public void setClassification(ArrayList<Top> classification) {
        this.classification = classification;
    }
}

我的顶级

public class Top {

    private Map<String, Day> day;

    public Map<String, Day> getDay() {
        return day;
    }

    public void setDay(Map<String, Day> day) {
        this.day = day;
    }
}

我的一天

public class Day {

    private String title;
    private String start;
    private String finish;

    private Map<String, Rankings> rankings;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getStart() {
        return start;
    }

    public void setStart(String start) {
        this.start = start;
    }

    public String getFinish() {
        return finish;
    }

    public void setFinish(String finish) {
        this.finish = finish;
    }

    public Map<String, Rankings> getRankings() {
        return rankings;
    }

    public void setRankings(Map<String, Rankings> rankings) {
        this.rankings = rankings;
    }
}

我的小组

public class Group1 {

    private Map<String, Club> club;
    private String difference;


    public Map<String, Club> getClub() {
        return club;
    }

    public void setClub(Map<String, Club> club) {
        this.club = club;
    }

    public String getDifference() {
        return difference;
    }

    public void setDifference(String difference) {
        this.difference = difference;
    }


}

但问题是我不知道如何编制排名等级#34; 1&#34; &#34; 2&#34; &#34; 3&#34;

你可以帮我吗

1 个答案:

答案 0 :(得分:0)

尝试使用this website,您可以在其中输入JSON字符串,并为您生成Java类。

编辑:

在网站上试用这个经过修改的JSON,它应该生成你的Java模型:

{
   "channel":{
      "title":"jeux"
   },
   "classification":{
      "day":{
         "id":"3175",
         "accr":"J5",
         "type":"0",
         "title":"xxxxxxxx",
         "start":"2016-09-17",
         "finish":"2016-09-18",
         "poolid":"36",
         "pool_name":null,
         "rankings":{
            "1":{
               "cal":{
                  "id":"12",
                  "name":"yyyyy",
                  "logo":{
                     "titre":"sssssssssssssssssssss.png",
                     "date":"2014-12-08 15:23:49",
                     "fichier":"image/png",
                     "url":"http://www.qWSi",
                     "taille":23528,
                     "largeur":116,
                     "hauteur":150
                  }
               },
               "difference":"65",
               "points":"18"
            },
            "2":{
               "cal":{
                  "id":"41",
                  "name":"aaaaaa",
                  "logo":{
                     "titre":"fsdfdsfsddf.png",
                     "date":"2016-07-06 15:35:01",
                     "fichier":"image/png",
                     "url":"http://www.M8ZBH1Be",
                     "taille":23475,
                     "largeur":122,
                     "hauteur":150
                  }
               },
               "difference":"65",
               "points":"18"
            }
         }
      }
   }
}