你好,我有这个json响应:
{
"brands":[{
"brand_name" : "VEJA",
"brand_id" : 114
},{
"brand_name" : "KENZO",
"brand_id" : 26
},{
"brand_name" : "POLO RALPH LAUREN",
"brand_id" : 40
},{
"brand_name" : "BALENCIAGA",
"brand_id" : 5
},{
"brand_name" : "BARBOUR",
"brand_id" : 146
},{
"brand_name" : "FAGUO",
"brand_id" : 12
},{
"brand_name" : "BENETTON",
"brand_id" : 117
},{
"brand_name" : "ASOS",
"brand_id" : 4
},{....}
这些是我的POJO类:
品牌类
public class Brand {
@SerializedName("brand_name")
@Expose
private String brandName;
@SerializedName("brand_id")
@Expose
private int brandId;
public String getBrandName() {
return brandName;
}
public void setBrandName(String brandName) {
this.brandName = brandName;
}
public int getBrandId() {
return brandId;
}
public void setBrandId(int brandId) {
this.brandId = brandId;
}
}
品牌类
public abstract class Brands {
@SerializedName("brands")
@Expose
private List<Brand> brands = null;
public List<Brand> getBrands() {
return brands;
}
public void setBrands(List<Brand> brands) {
this.brands = brands;
}
}
这是我的通话方法
final Call<Brands> brands = apiInterface.getBrands("// id ","// key"," //version");
brands.enqueue(new Callback<Brands>() {
@Override
public void onResponse(Call<Brands> call, Response<Brands> response) {
Brands brands1=response.body();
if(brands!=null) {
List<Brand> listBrands=brands1.getBrands();
}
Log.w("RESPONSE => ", new GsonBuilder().setPrettyPrinting().create().toJson(response));
}
我的api界面:
@GET("file.php")
Call<Brands> getBrands(
@Query("id_user")String id_user,@Query("key") String key,@Query("version") String version);
我仍然收到错误消息:
无法调用无参数的public(包名称).model.brand.Brands()
将品牌添加到列表中的方式是否有问题? 如何正确获取品牌名称和ID列表?