我知道这不是第一次有人问这个问题,但与Retrofit2我找不到正确的解决方案,我的问题。
我有一个包含String列表的对象。当我想JSON响应转换成我的对象的所有其他领域都OK,但我得到这个错误字符串列表转换到我的清单:
Retrofit2: Expected BEGIN_ARRAY but was STRING at line 1 column 268 path $[0].images
这是我的API:
@POST("/cp/api/")// get list of products
Call<List<Product>> Get_Special_Products(@Body Object request);
我改造设置:
public Retrofit Store_retrofit(OkHttpClient client) {
return new Retrofit.Builder()
.baseUrl(Urls.Sotre_Base_Url)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
我的对象:
public class Product implements Serializable {
@SerializedName("id")
private int id;
@SerializedName("user_id")
private int user_id;
@SerializedName("cat_id")
private int cat_id;
@SerializedName("title")
private String title;
@SerializedName("description")
private String description;
@SerializedName("image")
private String image;
@SerializedName("images")
private List<String> images;
public int getUser_id() {
return user_id;
}
public int getCat_id() {
return cat_id;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getImage() {
return image;
}
public List<String> getImages() {
return images;
}
}
,这导致错误的图像JSON的一部分:
images:[
"1487801544.jpg","1487801544.jpg","1487801544.jpg"
]
我猜你的回应正在改变图像的数量。检查一个图像的情况下是否返回对象 –
我认为你应该检查来自你的api的响应,这个错误通常是由不正确的响应格式引起的。 –
@HammadAkram谢谢,我发现问题,错误类型的数据来自服务器。 –