0
votes

Getting below error for the Gson parsing for below JSON

11-05 15:34:00.882: W/System.err(28673): com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 5923

 {
  "lab": [
    [
      {
        "id": "147",
        "messagelab_id": "test",
        "patientlab_ic": "abc",
        "patientlab_name": "some text"

      }
    ]
  ]
}

i have used below model classes for above JSON

public class ScreeningResults implements Serializable{

    private Labs lab;
    //@SerializedName("all_results")
    //private List<LabResult> labResults;

    public Labs getLab() {
        return lab;
    }
    public void setLab(Labs lab) {
        this.lab = lab;
    }


}


public class Labs implements Serializable{

 private List<Lab> lab;

public List<Lab> getLab() {
    return lab;
}

public void setLab(List<Lab> lab) {
    this.lab = lab;
}


}

i am using belo lines to parse serialize above JSON

Gson gson = new Gson();
  ScreeningResults screeningResults=gson.fromJson(response.toString(),ScreeningResults.class);
2
your json is invalid,replace "some text", to "some text" - Giru Bhai
Edited assume JSON is valid - kondal
As your json sturcture is like this "lab": [ [ so it must be List<List<Lab>> - amit kumar
Instead of lists, it should also be happy with Lab[][]. When you say Labs lab if looks for "lab" : { /* content defined in Labs class */ }, i.e. an object - zapl
@zap1 I have chnaged to private List<List<Lab>> lab; not its working - kondal

2 Answers

2
votes

The JSON contains a two-dimensional array. So instead of List<Lab> you should parse it to List<List<Lab>>.

0
votes

Here is the working Domain class for above JSON

@SuppressWarnings("serial")
public class ScreeningResults implements Serializable{

//private Labs lab;
private List<List<Lab>> lab;


public List<List<Lab>> getLab() {
    return lab;
}

public void setLab(List<List<Lab>> lab) {
    this.lab = lab;
}