Search code examples
androidapigsonretrofit2pojo

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 3 path $[0]


I am facing issue while calling the api. Can anyone help me the resolve the exception.

   JSON FORMAT:
[
[
{“id”:”1”},
{“id”:”1”}
],[],[]
]

MODEL:
public List<Data> data;

 Public class Data{
@SerializedName("id")
public String id;
}

CALLING:
Call <List<IndividualListModel>> indiList(@Header("Authorization") String token);

Solution

  • At the root element, the JSON that you receive doesn't have a List<Data>. It has List<List<Data>> since there are some arrays, nested inside another array:

    [
      [
        {
          "id": "1"
        },
        {
          "id": "1"
        }
      ],
      [],
      []
    ]