gpt4 book ai didi

android - 在 android 中改造带有 json 数组名称的响应对象

转载 作者:搜寻专家 更新时间:2023-11-01 09:25:08 25 4
gpt4 key购买 nike

我正在尝试将改造集成到我现有的一个项目中。我已将所有 API 转换为改造并停留在一个 API 中。 API 提供 JSON 数组,但没有名称。我无法为我的 json 数组准备响应模型。

回复:

[
{
"id": -1,
"colour": "Other"
},
{
"id": 1,
"colour": "None"
},
{
"id": 2,
"colour": "Aquamarine"
},
{
"id": 3,
"colour": "Arizona Grey"
},
{
"id": 4,
"colour": "Army Green"
},
{
"id": 5,
"colour": "Beige Blue"
},

{
"id": 269,
"colour": "Urban Titanium"
}
]

我正在尝试构建这样的响应模型。

    public class ColorResponse{

@SerializedName("id")
@Expose
private Integer id;
@SerializedName("colour")
@Expose
private String colour;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getColour() {
return colour;
}

public void setColour(String colour) {
this.colour = colour;
}

}

这里我只从我的 json 数组中获取一种颜色。

谁能帮我解决这个问题。

最佳答案

 Call<List<ColorResponse>> getColors()

像上面那样列出 ColorResponse 类对象,这对您有用。

关于android - 在 android 中改造带有 json 数组名称的响应对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51277202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com