При получении данных из открытого API погоды я получаю нули. Я использую retroFit2 в пределах android, чтобы получить данные. Вот сообщение из журнала:
onResponse: server response Response{protocol=http/1.1, code=200, message=OK,
onResponse: WeatherResponse{weather=com.weatherapp.models.Weather@197d237}
Вот GSON:
{
"coord": {
"lon": -5.93,
"lat": 54.58
},
"weather": [
{
"id": 804,
"main": "Clouds",
"description": "overcast clouds",
"icon": "04d"
}
],
"base": "stations",
"main": {
"temp": 293.15,
"feels_like": 288.01,
"temp_min": 293.15,
"temp_max": 293.15,
"pressure": 1024,
"humidity": 37
},
"visibility": 10000,
"wind": {
"speed": 5.7,
"deg": 160
},
"clouds": {
"all": 96
},
"dt": 1590770221,
"sys": {
"type": 1,
"id": 1376,
"country": "GB",
"sunrise": 1590724667,
"sunset": 1590785095
},
МОДЕЛЬ
@SerializedName("coord")
@Expose
private CoOrdinateModel coOrdinateModel;
@SerializedName("weather")
@Expose
private WeatherModel[] weatherModel;
@SerializedName("main")
@Expose
private MainModel main;
@SerializedName("visibility")
@Expose
private String visibility;
@SerializedName("wind")
@Expose
private WindModel wind;
ОТВЕТ
public class WeatherResponse {
@SerializedName("coord")
@Expose()
private Weather weather;
public Weather getWeather() {
return weather;
}
@Override
public String toString() {
return "WeatherResponse{" +
"weather=" + weather +
'}';
}
}
API
@GET("/data/2.5/weather")
Call<WeatherResponse> getWeather(
@Query("id") String ID,
@Query("APPID") String API_KEY
);
В идеале мне нужны почти все данные из GSON для анализа на объекты java в приложении android. Я делал это раньше с более простым GSON, но у этого есть массивы внутри, и я не уверен, что мой класс MODEL выполнен правильно, чтобы приспособиться к этому.
Любая помощь в определении root причины Нулевые значения были бы очень признательны