0

I am getting following error when I convert json to gson :

E/AndroidRuntime(1142): com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 51

I have json like this :

  {

"ResultCode": "0",
"ErrorMessage": null,
"Payload": [
    {
        "Items": [
            {
                "Title": "Star Wars"
            },
            { … },
            { … },
            { … },
            { … },
            { … },
            { … },
            { … },
            { … },
            { … },
            { … }
        ]
    },
    {
        "Items": [ … ]
    },
    {
        "Items": [ … ]
    }
]

} 

I have two classes : MResult class

 import java.util.List;

 public class MResult{
private String ErrorMessage;   
private String ResultCode;
private List<List<Item>> Payload;

public String getErrorMessage() {
    return ErrorMessage;
}
public void setErrorMessage(String errorMessage) {
    ErrorMessage = errorMessage;
}
public String getResultCode() {
    return ResultCode;
}
public void setResultCode(String resultCode) {
    ResultCode = resultCode;
}
public List<List<Item>> getPayload() {
    return Payload;
}
public void setPayload(List<List<Item>> payload) {
    Payload = payload;
}

}

Item class :

 public class Item{

private String Title;

 public String getTitle() {
    return Title;
}
public void setTitle(String title) {
    Title = title;
}

 }

I am getting the error on this line :

 MResult serviceResult = new Gson().fromJson(result,MResult.class);

1 Answer 1

1

You need another class to hold Items

List<Foo> Payload;

class Foo{
   List<Item> Items;
}
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.