【问题标题】:how to convert this JSON format into model class and get response into list using retrofit如何将此 JSON 格式转换为模型类并使用改造将响应转换为列表
【发布时间】:2021-10-12 08:05:57
【问题描述】:
    {
  "data": [
    {
      "resource": "teams",
      "id": 1,
      "name": "Pakistan",
      "code": "PAK",
      "image_path": "https://cdn.sportmonks.com/images/cricket/teams/1/1.png",
      "country_id": 190324,
      "national_team": true,
      "updated_at": "2018-11-29T11:47:20.000000Z"
    }
]
}

【问题讨论】:

    标签: android json api retrofit retrofit2


    【解决方案1】:

    在此处查看使用 java sample code 编写的示例代码

    或查看similar question

    或查看youtube course

    【讨论】:

      【解决方案2】:

      你可以有这样的东西

      public class Response{
          private List<Data> data;
          // getter and setter
      }
      
      class Data{
          private String resource;
          private int id;
          private String name;
          private String code;
          @SerializedName("image_path")
          private String imagePath;
          @SerializedName("country_id")
          private long countryId;
          @SerializedName("national_team")
          private boolean nationalTeam;
          @SerializedName("updated_at")
          private String updatedAt;
      
          // getters and setters
      }
      

      【讨论】:

        猜你喜欢
        • 2020-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-21
        • 1970-01-01
        • 1970-01-01
        • 2014-12-08
        • 1970-01-01
        相关资源
        最近更新 更多