2

I am not so new to Android, but started using retrofit today, I was able to clear all errors, now the response body returns null. I know its something to do with the way my class is set up. I have no idea how to handle an array with arrays. Any help would be appreciated. Thanks

[JSON return[1]

My Interface

  @GET("/web-api.php?route=feed/web_api/products")
 Call<Product>  loadProducts(@Query("category") Integer id, @Query("key")         String apiKey);

Class

public class Product implements Serializable {
@SerializedName("id")
private long mId;
@SerializedName("name")
private String mname;
@SerializedName("description")
private String mText;
@SerializedName("price")
private Double mprice;
@SerializedName("href")
private String mproductURL;
@SerializedName("thumb")
private String mImageURL;

public Product(long mId, String mname, String mText, Double mprice, String mproductURL, String mImageURL) {
    this.mId = mId;
    this.mname = mname;
    this.mText = mText;
    this.mprice = mprice;
    this.mproductURL = mproductURL;
    this.mImageURL = mImageURL;
}

public long getmId() {
    return mId;
}

public void setmId(long mId) {
    this.mId = mId;
}

public String getMname() {
    return mname;
}

public void setMname(String mname) {
    this.mname = mname;
}

public String getmText() {
    return mText;
}

public void setmText(String mText) {
    this.mText = mText;
}

public Double getMprice() {
    return mprice;
}

public void setMprice(Double mprice) {
    this.mprice = mprice;
}

public String getMproductURL() {
    return mproductURL;
}

public void setMproductURL(String mproductURL) {
    this.mproductURL = mproductURL;
}

public String getmImageURL() {
    return mImageURL;
}

public void setmImageURL(String mImageURL) {
    this.mImageURL = mImageURL;
}


@Override
public String toString() {
    return mText;
}

}

1
  • Your Retrofit class doesn't match the response. You need an object with a boolean value and an Arraylist of Products Commented Jun 30, 2016 at 14:02

1 Answer 1

1

Just define a Super class -

public class ResponseDS{
    public boolean success;
    public Product[] products;
}

And use ResponseDS instead of Product class -

 @GET("/web-api.php?route=feed/web_api/products")
 Call<ResponseDS>  loadProducts(@Query("category") Integer id, @Query("key")         String apiKey);

Hope it will help :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.