Possible Duplicate:
GSON throwing “Expected BEGIN_OBJECT but was BEGIN_ARRAY”?
Scenario : I am parsing an API which is is JSON format using GSON library. Here the JSON file I am parsing :
{
"questions": [
{
"question_1": "Question 1",
"options": [
"option_1 : option1",
"option_2 : option2",
"option_3 : option 3",
"option_4 : option 4"
]
},
{
"question_2": "Question 2",
"options": [
"option_1 : option 1",
"option_2 : option 2",
"option_3 : option 3"
]
}
]
}
And my object class looks like this :
public class Practise_Question_Object {
public List<Questions> questions;
public class Questions {
@SerializedName("question")
public String Question;
public List<Options> options;
public class Options {
public String Option_1;
public String Option_2;
public String Option_3;
public String Option_4;
}
}
Problem
My problem is that whenever I try to parse values It show me error java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 53
if I chagne "options" from Array to Object then I can easily parse. But in my project (From PHP side) i cant use Object.
What if you change this line:
to:
It looks like your JSON contains an array of
Options
objects.Otherwise can I suggest posting the actual code you use in the web service, just to confirm that you are using the GSOM DOM-style automatic parsing.