Я новичок в программировании на Android и хочу создать приложение погоды, используя openweathermap
api, например https://openweathermap.org/forecast5
Вот скриншот json parse
Я использую библиотеку loopj, чтобы получить json, но мой json неполон
вот так:
{"cod": "200","message": 0.0066,"cnt": 40,"list": [{"dt": 1555858800,"main": {"temp": 21.59,"temp_min": 20.06,"temp_max": 21.59,"pressure": 1021.117,"sea_level": 1021.117,"grnd_level": 1016.364,"humidity": 32,"temp_kf": 1.53},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01d"}],"clouds": {"all": 1},"wind": {"speed": 2.01,"deg": 60.266},"sys": {"pod": "d"},"dt_txt": "2019-04-21 15:00:00"}, {"dt": 1555869600,"main": {"temp": 16.4,"temp_min": 15.25,"temp_max": 16.4,"pressure": 1020.284,"sea_level": 1020.284,"grnd_level": 1015.421,"humidity": 48,"temp_kf": 1.15},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01d"}],"clouds": {"all": 1},"wind": {"speed": 2.38,"deg": 65.618},"sys": {"pod": "d"},"dt_txt": "2019-04-21 18:00:00"}, {"dt": 1555880400,"main": {"temp": 12.82,"temp_min": 12.05,"temp_max": 12.82,"pressure": 1020.702,"sea_level": 1020.702,"grnd_level": 1016.031,"humidity": 53,"temp_kf": 0.77},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01n"}],"clouds": {"all": 0},"wind": {"speed": 3.56,"deg": 71.203},"sys": {"pod": "n"},"dt_txt": "2019-04-21 21:00:00"}, {"dt": 1555891200,"main": {"temp": 10.07,"temp_min": 9.69,"temp_max": 10.07,"pressure": 1020.36,"sea_level": 1020.36,"grnd_level": 1015.763,"humidity": 51,"temp_kf": 0.38},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01n"}],"clouds": {"all": 0},"wind": {"speed": 3.03,"deg": 77.056},"sys": {"pod": "n"},"dt_txt": "2019-04-22 00:00:00"}, {"dt": 1555902000,"main": {"temp": 7.67,"temp_min": 7.67,"temp_max": 7.67,"pressure": 1019.373,"sea_level": 1019.373,"grnd_level": 1014.778,"humidity": 55,"temp_kf": 0},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01n"}],"clouds": {"all": 0},"wind": {"speed": 2.86,"deg": 81.541},"sys": {"pod": "n"},"dt_txt": "2019-04-22 03:00:00"}, {"dt": 1555912800,"main": {"temp": 9.37,"temp_min": 9.37,"temp_max": 9.37,"pressure": 1019.229,"sea_level": 1019.229,"grnd_level": 1014.565,"humidity": 55,"temp_kf": 0},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01d"}],"clouds": {"all": 0},"wind": {"speed": 3.8,"deg": 86.484},"sys": {"pod": "d"},"dt_txt": "2019-04-22 06:00:00"}, {"dt": 1555923600,"main": {"temp": 14.35,"temp_min": 14.35,"temp_max": 14.35,"pressure": 1018.632,"sea_level": 1018.632,"grnd_level": 1014.264,"humidity": 48,"temp_kf": 0},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01d"}],"clouds": {"all": 0},"wind": {"speed": 5.64,"deg": 99.312},"sys": {"pod": "d"},"dt_txt": "2019-04-22 09:00:00"}, {"dt": 1555934400,"main": {"temp": 17.55,"temp_min": 17.55,"temp_max": 17.55,"pressure": 1017.309,"sea_level": 1017.309,"grnd_level": 1012.749,"humidity": 38,"temp_kf": 0},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01d"}],"clouds": {"all": 0},"wind": {"speed": 6.35,"deg": 98.558},"sys": {"pod": "d"},"dt_txt": "2019-04-22 12:00:00"}, {"dt": 1555945200,"main": {"temp": 17.71,"temp_min": 17.71,"temp_max": 17.71,"pressure": 1015.852,"sea_level": 1015.852,"grnd_level": 1011.075,"humidity": 39,"temp_kf": 0},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01d"}],"clouds": {"all": 0},"wind": {"speed": 7.39,"deg": 100.356},"sys": {"pod": "d"},"dt_txt": "2019-04-22 15:00:00"}, {"dt": 1555956000,"main": {"temp": 14.21,"temp_min": 14.21,"temp_max": 14.21,"pressure": 1015.413,"sea_level": 1015.413,"grnd_level": 1010.796,"humidity": 51,"temp_kf": 0},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01d"}],"clouds": {"all": 0},"wind": {"speed": 5.54,"deg": 100.271},"sys": {"pod": "d"},"dt_txt": "2019-04-22 18:00:00"}, {"dt": 1555966800,"main": {"temp": 13.05,"temp_min": 13.05,"temp_max": 13.05,"pressure": 1015.546,"sea_level": 1015.546,"grnd_level": 1010.792,"humidity": 59,"temp_kf": 0},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01n"}],"clouds": {"all": 0},"wind": {"speed": 6.03,"deg": 94.728},"sys": {"pod": "n"},"dt_txt": "2019-04-22 21:00:00"}, {"dt": 1555977600,"main": {"temp": 11.87,"temp_min": 11.87,"temp_max": 11.87,"pressure": 1014.771,"sea_level": 1014.771,"grnd_level": 1009.838,"humidity": 65,"temp_kf": 0},"weather": [{"id": 800,"main": "Clear","description": "clear sky","icon": "01n"}],
полный json здесь:
http://www.jsonmate.com/permalink/5cbd441c85da04b10bcf80e5
Это мой код для запроса информации:
final String UA5 = "http://api.openweathermap.org/data/2.5/forecast";
private void getjson(RequestParams params) {
AsyncHttpClient httpClient = new AsyncHttpClient();
httpClient.get(UA5, params, new JsonHttpResponseHandler() {
@Override
public void onStart() {
// called before request is started
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response2) {
// called when response HTTP status is "200 OK"
Log.d("Result",response2.toString());
try {
time0 =response2.getJSONArray("list").getJSONObject(0).getString("dt_txt");
time1=response2.getJSONArray("list").getJSONObject(1).getString("dt_txt");
time2=response2.getJSONArray("list").getJSONObject(2).getString("dt_txt");
time3=response2.getJSONArray("list").getJSONObject(3).getString("dt_txt");
time4=response2.getJSONArray("list").getJSONObject(4).getString("dt_txt");
time5=response2.getJSONArray("list").getJSONObject(5).getString("dt_txt");
time6=response2.getJSONArray("list").getJSONObject(6).getString("dt_txt");
time7=response2.getJSONArray("list").getJSONObject(7).getString("dt_txt");
time8=response2.getJSONArray("list").getJSONObject(8).getString("dt_txt");
time9=response2.getJSONArray("list").getJSONObject(9).getString("dt_txt");
time10=response2.getJSONArray("list").getJSONObject(10).getString("dt_txt");
time11=response2.getJSONArray("list").getJSONObject(11).getString("dt_txt");
time12=response2.getJSONArray("list").getJSONObject(12).getString("dt_txt");
time13=response2.getJSONArray("list").getJSONObject(13).getString("dt_txt");
time14=response2.getJSONArray("list").getJSONObject(14).getString("dt_txt");
time15=response2.getJSONArray("list").getJSONObject(15).getString("dt_txt");
time16=response2.getJSONArray("list").getJSONObject(16).getString("dt_txt");
time17=response2.getJSONArray("list").getJSONObject(17).getString("dt_txt");
time18=response2.getJSONArray("list").getJSONObject(18).getString("dt_txt");
time19=response2.getJSONArray("list").getJSONObject(19).getString("dt_txt");
time20=response2.getJSONArray("list").getJSONObject(20).getString("dt_txt");
time21=response2.getJSONArray("list").getJSONObject(21).getString("dt_txt");
time22=response2.getJSONArray("list").getJSONObject(22).getString("dt_txt");
time23=response2.getJSONArray("list").getJSONObject(23).getString("dt_txt");
time24=response2.getJSONArray("list").getJSONObject(24).getString("dt_txt");
time25=response2.getJSONArray("list").getJSONObject(25).getString("dt_txt");
time26=response2.getJSONArray("list").getJSONObject(26).getString("dt_txt");
time27=response2.getJSONArray("list").getJSONObject(27).getString("dt_txt");
time28=response2.getJSONArray("list").getJSONObject(28).getString("dt_txt");
time29=response2.getJSONArray("list").getJSONObject(29).getString("dt_txt");
time30=response2.getJSONArray("list").getJSONObject(30).getString("dt_txt");
time31=response2.getJSONArray("list").getJSONObject(31).getString("dt_txt");
time32=response2.getJSONArray("list").getJSONObject(32).getString("dt_txt");
time33=response2.getJSONArray("list").getJSONObject(33).getString("dt_txt");
time34=response2.getJSONArray("list").getJSONObject(34).getString("dt_txt");
time35=response2.getJSONArray("list").getJSONObject(35).getString("dt_txt");
time36=response2.getJSONArray("list").getJSONObject(36).getString("dt_txt");
time37=response2.getJSONArray("list").getJSONObject(37).getString("dt_txt");
time38=response2.getJSONArray("list").getJSONObject(38).getString("dt_txt");
time39=response2.getJSONArray("list").getJSONObject(39).getString("dt_txt");
time40=response2.getJSONArray("list").getJSONObject(40).getString("dt_txt");
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable e, JSONObject errorResponse) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
}
@Override
public void onRetry(int retryNo) {
// called when request is retried
}
});
}
, и это мой код в onCreate:
CityName : это название города, в который я отправил запрос
App_ID : мой ключ API
RequestParams params = new RequestParams();
params.put("q", CityNme);
params.put("appid", App_ID);
params.put("units", "metric");
getjson(params);
Кто-нибудь, кто меня направляет?
Спасибо.