0% found this document useful (0 votes)
18 views

JSONObject Jsonobject

The document parses JSON data from a weather API response to extract information like city name, date, temperature, humidity, wind speed, cloud coverage, and country. It uses the JSON data to populate text views for display on an app interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

JSONObject Jsonobject

The document parses JSON data from a weather API response to extract information like city name, date, temperature, humidity, wind speed, cloud coverage, and country. It uses the JSON data to populate text views for display on an app interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

JSONObject jsonobject= new JSONObject(response);

String day= jsonobject.getString("dt");


String name = jsonobject.getString("name");
txtcity.setText(" Tên Thành Phố: "+name);
long l = Long.valueOf(day);
Date date = new Date(l*1000L);
SimpleDateFormat simpleDateFormat = new
SimpleDateFormat("EEEE yyyy-MM-dd HH-mm-ss ");
String Day = simpleDateFormat.format(date);

txtday.setText(Day);
JSONArray jsonArrayWeather =
jsonobject.getJSONArray("weather");
JSONObject jsonObjectweather =
jsonArrayWeather.getJSONObject(0);
String status = jsonObjectweather.getString("main");
String icon = jsonObjectweather.getString("icon");

Picasso.get().load("http://openweathermap.org/img/wn/"+icon+".png").into(ImgIcon);
txtstatus.setText(status);

JSONObject jsonObjectMain =
jsonobject.getJSONObject("main");
String nhietdo= jsonObjectMain.getString("temp");
String doam = jsonObjectMain.getString("humidity");
Double a= Double.valueOf(nhietdo);
String Nhietdo = String.valueOf(a.intValue());
txttemp.setText(nhietdo+"C");
txthumidity.setText(doam+"%");

JSONObject jsonObjectWind = jsonobject.getJSONObject("wind");


String gio= jsonObjectWind.getString("speed");
txtWind.setText(gio+"m/s");

JSONObject jsonObjectCloud = jsonobject.getJSONObject("Cloud");


String may = jsonObjectCloud.getString("all");
txtCloud.setText((may+"%"));

JSONObject jsonObjectSys = jsonobject.getJSONObject("sys");


String country = jsonObjectSys.getString("country");
txtcountry.setText("Ten quoc gia: " + country);

You might also like