Я сейчас работаю над своего рода погодным приложением. Для этого я должен проанализировать объект JSON. Я использую GSON для этого.
Я всегда получаю ошибку.
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: ожидается BEGIN_OBJECT, но было
BEGIN_ARRAY в строке 1 столбца 224 путь $ .list [0] .weather
Объект JSON выглядит примерно так:
{"city":{"id":1851632,"name":"Shuzenji"},
"coord":{"lon":138.933334,"lat":34.966671},
"country":"JP",
"cod":"200",
"message":0.0045,
"cnt":38,
"list":[{
"dt":1406106000,
"main":{
"temp":298.77,
"temp_min":298.77,
"temp_max":298.774,
"pressure":1005.93,
"sea_level":1018.18,
"grnd_level":1005.93,
"humidity":87,
"temp_kf":0.26},
"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],
"clouds":{"all":88},
"wind":{"speed":5.71,"deg":229.501},
"sys":{"pod":"d"},
"dt_txt":"2014-07-23 09:00:00"},
{
"dt":1406106000,
"main":{
"temp":298.77,
"temp_min":298.77,
"temp_max":298.774,
"pressure":1005.93,
"sea_level":1018.18,
"grnd_level":1005.93,
"humidity":87,
"temp_kf":0.26},
"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],
"clouds":{"all":88},
"wind":{"speed":5.71,"deg":229.501},
"sys":{"pod":"d"},
"dt_txt":"2014-07-23 09:00:00"}
]}
Я создал все классы, необходимые для объекта "все в одном":
public class AIOobject {
City city;
Coord coord;
String country;
String cod;
String message;
String cnt;
List[] list;
public AIOobject(City city, Coord coord, String country, String cod, String message, String cnt, List[] list) {
this.city = city;
this.coord = coord;
this.country = country;
this.cod = cod;
this.message = message;
this.cnt = cnt;
this.list = list;
}
}
Другие классы просто сохраняют данные, например:
public class Weather {
String id;
String main;
String description;
String icon;
public Weather(String id, String main, String description, String icon) {
this.id = id;
this.main = main;
this.description = description;
this.icon = icon;
}
}
Теперь у меня вопрос, почему я получаю эту ошибку и как я могу решить эту проблему.
Спасибо за все ответы
РЕДАКТИРОВАТЬ Исправлен объект JSON
~ Пол