简体   繁体   English

如何在android中使用改造解析json

[英]How to parse json with retrofit in android

please I need your help, I want to parse the following json in my app with retrofit in android, but the problem is that I don't know how to create my model classes, I want to show title, rankings, name, titre, difference and points of each ranking,请我需要你的帮助,我想在我的应用程序中解析以下 json 并在 android 中进行改造,但问题是我不知道如何创建我的模型类,我想显示标题、排名、名称、标题,每个排名的差异和积分,

My json:我的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我的前 14

{
"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 top14lst我的第 14 名

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;
    }
}

my top我的顶

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;
    }
}

my 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;
    }
}

my group我的组

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;
    }


}

but the problem i don't know how to code the ranking class "1" "2" "3"但问题是我不知道如何对排名等级“1”“2”“3”进行编码

can you please help me你能帮我么

Try this website , where you can enter your JSON string and it generates the Java Class for you.试试这个网站,您可以在其中输入您的 JSON 字符串,它会为您生成 Java 类。

Edit:编辑:

Try this modified JSON with the website and it should generate your Java models:在网站上试试这个修改过的 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"
            }
         }
      }
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM