Android – retrofit2: expected begin_ Array but string is in line 1, line 268, path $[0]. Images

I know this is not the first time someone has asked this question, but I can't find the right way to solve the problem with retrofit 2

I have an object containing a string list. When I want to convert the JSON response to my object, all other fields can be used, but this error occurs when I convert this string list to my list:

Retrofit2: Expected BEGIN_ARRAY but was STRING at line 1 column 268 path $[0].images

This is my API:

@POST("/cp/api/")// get list of products
    Call<List<Product>> Get_Special_Products(@Body Object request);

My transformation settings:

public Retrofit Store_retrofit(OkHttpClient client) {
        return new Retrofit.Builder()
                .baseUrl(Urls.sotre_Base_Url)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

My target:

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

This is part of the JSON that caused the image error:

images:[
    "1487801544.jpg","1487801544.jpg","1487801544.jpg"
]

resolvent:

This usually happens when your API service cannot convert an array to JSON and retrofit reads it as string. Call your API service provider to solve the problem of converting an array to JSON:) for example

"images": "[\"1487801544.jpg\",\"1487801544.jpg\",\"148801544.jpg\"]"

If it is modified to read as a string above, it should be changed as follows:

"images": [
      "1487801544.jpg",
      "1487801544.jpg",
      "1487801544.jpg"
    ]

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>