Android : Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 52
-
24-12-2019 - |
Question
I get a json response returned by a web service.
{
"status":{
"msg":"success",
"code":0
},
"timezones":[
[
"US/Eastern",
"(UTC-05:00) Eastern Time"
],
[
"US/Central",
"(UTC-06:00) Central Time"
],
[
"US/Mountain",
"(UTC-07:00) Mountain Time"
],
[
"US/Pacific",
"(UTC-08:00) Pacific Time"
],
[
"US/Alaska",
"(UTC-09:00) Alaska"
],
[
"US/Hawaii",
"(UTC-10:00) Hawaii"
]
]
}
I am parsing this using gson.
public class TimeZonesResult
{
public ApiStatus status;
@SerializedName("timezones")
public JsonArray arrTimeZones;
}
ApiStatus is another class where I declare msg and code. But I have problem parsing timezones. I get "Android : Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 52 " returned by volley. Please help. Thanks in advance.
La solution
Try using a List<List<String>>
as the data type for arrTimeZones instead of a JsonArray
. http://www.jsonschema2pojo.org/ is a good resource for getting pojo representations of your json data correct.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow