hello i have Json
response like this
[
{
"question": "hhhhh",
"question_answer": "hhhh ",
"question_type": "question type",
"questioner_age": "questioner age",
"questioner_city": "questioner city",
"questioner_country": "questioner country",
"questioner_name": "questioner name",
"questioner_sex": "questioner sex",
"comments_allowed": "1",
"question_id": "63",
"question_date": "05/08/2017 - 19:33",
"is_public": "1"
},
{
"question": "hhhh !!",
"question_answer": "hhhh",
"question_type": [],
"questioner_age": [],
"questioner_city": [],
"questioner_country": [],
"questioner_name": "hhhhh",
"questioner_sex": [],
"comments_allowed": "1",
"question_id": "57",
"question_date": "04/30/2017 - 14:24",
"is_public": "1"
}
]
if the column is null will return as an array like this "question_type": [], if not will return as a string !
so i tried to get this response on retrofit but i failed and always got this error
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 4 column 2 path $
after i searched in the internet i tried something like this but its not working !!
Gson gson = new Gson();
String json = response.body().toString();
if (json instanceof String)
{
MyQuestionModelString parseObject = gson.fromJson(json, MyQuestionModelString.class);
apiCallResponse.onSuccess(parseObject,responseMessage);
}else {
MyQuestionModel parseObject = gson.fromJson(json, MyQuestionModel.class);
apiCallResponse.onSuccess(parseObject,responseMessage);
}
any help !
UPDATAE !
this is my model for this response and same error !!!
public class MyQuestionModel {
@SerializedName("question")
@Expose
private String question;
@SerializedName("question_answer")
@Expose
private String questionAnswer;
@SerializedName("question_type")
@Expose
private List<Object> questionType = null;
@SerializedName("questioner_age")
@Expose
private List<Object> questionerAge = null;
@SerializedName("questioner_city")
@Expose
private List<Object> questionerCity = null;
@SerializedName("questioner_country")
@Expose
private List<Object> questionerCountry = null;
@SerializedName("questioner_name")
@Expose
private String questionerName;
@SerializedName("questioner_sex")
@Expose
private List<Object> questionerSex = null;
@SerializedName("comments_allowed")
@Expose
private String commentsAllowed;
@SerializedName("question_id")
@Expose
private String questionId;
@SerializedName("question_date")
@Expose
private String questionDate;
@SerializedName("is_public")
@Expose
private String isPublic;
}
My Main issue that how to define this field ! question_type screen shot