Implement a simple weather forecast application (1)

Source: Internet
Author: User

Take a look at my own implementation of a weather forecast application process, this is not a completed application, each write down is the implementation of a phase, each phase to solve a problem.

1. Get the JSON data for the weather forecast

Because I did not want to use XML, in the evening to check for a long time to find a can be used to return the JSON weather request HTTP

This is

Http://www.k780.com/api/weather.future

An example of the build is given on this page:

http://api.k780.com:88/?app=weather.future&weaid=1&appkey=10003&sign= B59bc3ef6191eb9f747dd4e83c99f2a4&format=json

Weaid behind is the number of the Chinese weather Network defined by the city code, the following address is the Chinese weather Network given the code table

Http://openweather.weather.com.cn/Public/font/areaid_v.xlsx

Http://openweather.weather.com.cn/Public/font/areaid_f.xlsx

For example, Chengdu 101270101

I constructed the weather in Chengdu Query HTTP address (temporarily do not consider to allow users to customize the city), Appkey is required to register on this site to see, similarly sigin is also, free users can request 720 times/hour, their own use to say enough.

To facilitate the practice of using the Volly network Communication library at the same time, I use volly to request and accept JSON data as follows (in the oncreate of Mainactivity)

After you use it on your phone, you get the following data:

{"Result": [{"Temp_low": "7", "Cityno": "Chengdu", "Wind": "North", "citynm": "Chengdu", "Weaid": "265", "Winpid": "A", "Windid": "A", "WEATID1": "8", "Humi_high": "0", "Temperature": "12℃\/7℃", "Cityid": "101270101", "Temp_high": "A", "humidity": " 0℉\/0℉ "," Weather_icon ":" Http:\/\/api.k780.com:88\/upload\/weather\/d\/2.gif "," Days ":" 2015-03-03 "," Weatid ":" 3 ", "Humi_low": "0", "Weather": "Yin Turn drizzle", "WINP": "Breeze", "Weather_icon1": "Http:\/\/api.k780.com:88\/upload\/weather\/n\/7." GIF "," Week ":" Tuesday "},{" Temp_low ":" 5 "," Cityno ":" Chengdu "," Wind ":" North "," citynm ":" Chengdu "," Weaid ":" 265 "," Winpid ":" 125 "," Windid ":", "WEATID1": "8", "Humi_high": "0", "Temperature": "9℃\/5℃", "Cityid": "101270101", "Temp_high": "9", " Humidity ":" 0℉\/0℉ "," Weather_icon ":" Http:\/\/api.k780.com:88\/upload\/weather\/d\/7.gif "," Days ":" 2015-03-04 "," Weatid ":" 8 "," Humi_low ":" 0 "," Weather ":" Light Rain "," WINP ":" Breeze "," Weather_icon1 ":" http:\/\/api.k780.com:88\/upload\/ Weather\/n\/7.gif "," Week ":" Wednesday "},{" Temp_low ":" 4 "," Cityno ":" Chengdu "," Wind ":" North "," citynm ":" Chengdu "," Weaid ":" 265 "," Winpid ":", "Windid": "20 "," weatid1 ":" 2 "," Humi_high ":" 0 "," Temperature ":" 8℃\/4℃ "," Cityid ":" 101270101 "," Temp_high ":" 8 "," Humidity ":" 0℉\/ 0℉ "," Weather_icon ":" Http:\/\/api.k780.com:88\/upload\/weather\/d\/2.gif "," Days ":" 2015-03-05 "," Weatid ":" 3 "," Humi_low ":" 0 "," Weather ":" Overcast Turn cloudy "," WINP ":" Breeze "," Weather_icon1 ":" HTTP:\/\/API.K780.COM:88\/UPLOAD\/WEATHER\/N\/1. " GIF "," Week ":" Thursday "},{" Temp_low ":" 3 "," Cityno ":" Chengdu "," Wind ":" North winds turn South Wind "," citynm ":" Chengdu "," Weaid ":" 265 "," Winpid ":" 125 "," Windid ":" "," Weatid1 ":" 2 "," Humi_high ":" 0 "," Temperature ":" 14℃\/3℃ "," Cityid ":" 101270101 "," Temp_high ":" 14 "," Humidity ":" 0℉\/0℉ "," Weather_icon ":" Http:\/\/api.k780.com:88\/upload\/weather\/d\/1.gif "," Days ":" 2015-03-06 "," Weatid ":" 2 "," Humi_low ":" 0 "," Weather ":" Cloudy "," WINP ":" Breeze "," Weather_icon1 ":" http:\/\/api.k780.com:88\/upload\/ Weather\/n\/1.gif "," Week ":" Friday "},{" Temp_low ":" 5 "," Cityno ":" Chengdu "," Wind ":" Southerly "," citynm ":" Chengdu "," Weaid ":" 265 "," Winpid ":" "Windid": "5", "Weatid1": "2", "Humi_high": "0", "Temperature": "15℃\/5℃", "Cityid": "101270101", "Temp_ High ":", "humidity": "0℉\/0℉ "," Weather_icon ":" Http:\/\/api.k780.com:88\/upload\/weather\/d\/1.gif "," Days ":" 2015-03-07 "," Weatid ":" 2 "," Humi_low ":" 0 "," Weather ":" Cloudy "," WINP ":" Breeze "," Weather_icon1 ":" Http:\/\/api.k780.com:88\/upload\/weather\/n\/1.gif " , "Week": "Saturday"},{"Temp_low": "6", "Cityno": "Chengdu", "Wind": "South", "citynm": "Chengdu", "Weaid": "265", "Winpid": "125", " Windid ":" 5 "," Weatid1 ":" 2 "," Humi_high ":" 0 "," Temperature ":" 15℃\/6℃ "," Cityid ":" 101270101 "," Temp_high ":" 15 "," Humidity ":" 0℉\/0℉ "," Weather_icon ":" Http:\/\/api.k780.com:88\/upload\/weather\/d\/1.gif "," Days ":" 2015-03-08 "," Weatid ":" 2 "," Humi_low ":" 0 "," Weather ":" Cloudy "," WINP ":" Breeze "," Weather_icon1 ":" http:\/\/api.k780.com:88\/upload\/ Weather\/n\/1.gif "," Week ":" Sunday "},{" Temp_low ":" 6 "," Cityno ":" Chengdu "," Wind ":" Southerly "," citynm ":" Chengdu "," Weaid ":" 265 "," Winpid ":" "Windid": "5", "Weatid1": "2", "Humi_high": "0", "Temperature": "17℃\/6℃", "Cityid": "101270101", "Temp_ High ":", "humidity": "0℉\/0℉", "Weather_icon": "Http:\/\/api.k780.com:88\/upload\/weather\/d\/1.gif", "Days": " 2015-03-09 "," Weatid ":" 2 "," humi_low ":" 0 "," Weather ":" Cloudy "," WINP ":" Breeze "," Weather_icon1 ":" Http:\/\/api.k780.com:88\/upload\/weather\/n\/1.gif "," Week ":" Monday "}]," Success ":" 1 "}

It's obvious that this is a seven-day weather forecast from now on.

The next section is to resolve how to parse these JSON data, see the next article.

Implement a simple weather forecast application (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.