I am getting JSon data from a web service, the sample data is given below:
[
{
"SectionId": 1,
"SectionName": "Android"
}
]
When i try to convert it, it throws an error, i am doing it as:
Data data = new Gson().fromJson(jsonDataFromWebService, Data.class);
My Section Class is:
class Section
{
public int SectionId;
public String SectionName;
}
class Data {
public List<Section> sections;
}
The LogCat says:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
The error explains whats wrong… u r returning an array and not a JSon object
try as following: