1

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path

My interface looks like this

public interface UsersApi {
   @GET("/api/?results=20")
   Call<List<Result>> getData();
}

Json API

{
   "results": [
      {
         "gender":"female",
         "name":{
            "title":"Miss",
            "first":"Lana",
            "last":"Da Silva"
            }
      }
    ]
}
4
  • Please post your Result POJO Commented Jul 30, 2020 at 11:01
  • Here is my POJO class, posted on pastebin as it contains 80+ lines pastebin.com/vXSvejEp Commented Jul 30, 2020 at 11:12
  • You using retrofit? Can you post the initialization Commented Jul 30, 2020 at 11:17
  • similarly as I do it in cauldrons, but in it there is no error and in java is pastebin.com/v5TUP6gM Commented Jul 30, 2020 at 11:22

1 Answer 1

2

Please Create modal Class like below e.g.

public class Modal {

@SerializedName("results")
private List<Result> mResults;

public List<Result> getResults() {
    return mResults;
}

public void setResults(List<Result> results) {
    mResults = results;
}

}



public interface UsersApi {
@GET("/api/?results=20")
Call<Modal> getData();
}
Sign up to request clarification or add additional context in comments.

3 Comments

I really don't see how that is going to help when then Retrofit documentation advocates the way @stepan has done it square.github.io/retrofit
you can use Call<List<Repo>> if your response start from jsonArray in your case Your response satart from JsonObject. Your response: { "results": [ { "gender":"female", "name":{ "title":"Miss", "first":"Lana", "last":"Da Silva" } } ] } Required response :[ { "gender":"female", "name":{ "title":"Miss", "first":"Lana", "last":"Da Silva" } } ]
apologies I see what you mean now!

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.