在上一篇中,我们使用了XStream来解析XML(HttpClient 4发送请求)制作了一个电子商务小应用,本篇我们来解析另外一种使用广泛的数据交换技术JSON。
本文意在说明JACKSON组件解析JSON格式文本,并结合中央气象台的天气预报API来展示。天气预报的请求地址是:http://m.weather.com.cn/data/101070201.html,这个文本就是城市代码,101070201代表大连市,执行URL,得到一个返回文本,是JSON格式的,如下:
{"weatherinfo":{"city":"大连","city_en":"dalian","date_y":"2010年11月21日","date":"庚寅年十月十六","week":"星期日","fchh":"18","cityid":"101070201","temp1":"0℃~6℃","temp2":"1℃~9℃","temp3":"4℃~7℃","temp4":"-1℃~6℃","temp5":"-1℃~7℃","temp6":"-2℃~3℃","tempF1":"32ㄈ~42.8ㄈ","tempF2":"33.8ㄈ~48.2ㄈ","tempF3":"39.2ㄈ~44.6ㄈ","tempF4":"30.2ㄈ~42.8ㄈ","tempF5":"30.2ㄈ~44.6ㄈ","tempF6":"28.4ㄈ~37.4ㄈ","weather1":"多云转晴","weather2":"晴","weather3":"多云","weather4":"晴","weather5":"晴转多云","weather6":"多云转晴","img1":"1","img2":"0","img3":"0","img4":"99","img5":"1","img6":"99","img7":"0","img8":"99","img9":"0","img10":"1","img11":"1","img12":"0","img_single":"0","img_title1":"多云","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"多云","img_title6":"多云","img_title7":"晴","img_title8":"晴","img_title9":"晴","img_title10":"多云","img_title11":"多云","img_title12":"晴","img_title_single":"晴","wind1":"西北风5-6级转北风4-5级","wind2":"北风转南风4-5级","wind3":"南风4-5级转北风5-6级","wind4":"北风5-6级转4-5级","wind5":"北风转南风4-5级","wind6":"南风转北风4-5级","fx1":"西北风","fx2":"北风","fl1":"5-6级转4-5级","fl2":"4-5级","fl3":"4-5级转5-6级","fl4":"5-6级转4-5级","fl5":"4-5级","fl6":"4-5级","index":"凉","index_d":"天气凉,建议着厚外套加毛衣等春秋服装。年老体弱者宜着大衣、呢外套加羊毛衫。","index48":"凉","index48_d":"天气凉,建议着厚外套加毛衣等春秋服装。年老体弱者宜着大衣、呢外套加羊毛衫。","index_uv":"中等","index48_uv":"弱","index_xc":"较适宜","index_tr":"一般","index_co":"较不舒适","st1":"2","st2":"-4","st3":"7","st4":"1","st5":"5","st6":"1","index_cl":"较不宜","index_ls":"基本适宜"}}
字段言简意赅,城市名,英文名,日期,农历日期,星期,预报时间,城市代码,6个预报温度(华氏温度,摄氏温度),6个预报天气和风力,剩下的就是一些气象指数什么的了,本例我们仅仅拿当日的信息来说明。
这段文本是我们直接通过浏览器请求来的,但是在程序中如何进行?需要借助网络api的帮助,可以直接使用java网络api,也可以使用第三方类库,这里我们使用Apache的Commons组件中的HttpClient3来说明。首先建立项目工程,使用Maven管理:

引入的必要的依赖,如下:

Weather类是封装必要数据的Bean,很简单,如下:
package weather; public class Weather { private String city;// 城市名 private String date;// 日期:yyyy年MM月d日 private String lunarDate;// 农历日期/当日有 private String week;// 星期 private String fcTime;// 预报时间:24制小时数/当日有 private String temperature;// 当日气温 private String weather;// 天气 private String wind;// 风力 // 省略了getter和setter方法 @Override public String toString() { return "Weather [city=" + city + ", date=" + date + ", fcTime=" + fcTime + ", lunarDate=" + lunarDate + ", temperature=" + temperature + ", weather=" + weather + ", week=" + week + ", wind=" + wind + "]"; } }
下面就是示例代码了,很简单:
package weather; import java.util.HashMap; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.codehaus.jackson.JsonFactory; import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonToken; import org.codehaus.jackson.map.MappingJsonFactory; /** * 天气预报服务,解析JSON * * @author Nanlei * */ public class Demo { private static String URL = "http://m.weather.com.cn/data/101070201.html";// 请求的地址 private static HttpClient client; private static GetMethod getMethod; /** * 静态块初始化所需对象 */ static { client = new HttpClient(); getMethod = new GetMethod(URL); } /** * 获取获得的Json结果 * * @return */ public static String getJsonText() { String jsonText = null; try { int status = client.executeMethod(getMethod); if (status == HttpStatus.SC_OK) {// HTTP 200 OK jsonText = getMethod.getResponseBodyAsString();// 获取字符串形式的结果,建议使用流式结果 } } catch (Exception e) { System.err.println(e); } return jsonText; } /** * 处理Json结果并封装Bean * * @param jsonText * @return */ public static Weather getWeatherBean(String jsonText) { // Weather对象 Weather weather = new Weather(); try { JsonFactory jsonFactory = new MappingJsonFactory(); // Json解析器 JsonParser jsonParser = jsonFactory.createJsonParser(jsonText); // 跳到结果集的开始 jsonParser.nextToken(); // 接受结果的HashMap HashMap<String, String> map = new HashMap<String, String>(); // while循环遍历Json结果 while (jsonParser.nextToken() != JsonToken.END_OBJECT) { // 跳转到Value jsonParser.nextToken(); // 将Json中的值装入Map中 map.put(jsonParser.getCurrentName(), jsonParser.getText()); } // 将数据封装 weather.setCity(map.get("city")); weather.setDate(map.get("date_y")); weather.setLunarDate(map.get("date")); weather.setWeek(map.get("week")); weather.setFcTime(map.get("fchh")); weather.setTemperature(map.get("temp1")); weather.setWeather(map.get("weather1")); weather.setWind(map.get("wind1")); } catch (Exception e) { System.err.println(e); } return weather; } /** * 主函数 * * @param args */ public static void main(String[] args) { System.out.println(getWeatherBean(getJsonText())); } }
其中提供了获取JSON和处理JSON结果的方法,用法都很简单,这样就可以得到天气预报的结果了:
Weather [city=大连, date=2010年11月21日, fcTime=18, lunarDate=庚寅年十月十六, temperature=0℃~6℃, weather=多云转晴, week=星期日, wind=西北风5-6级转北风4-5级]
Jackson处理JSON非常简单,但要了解JSON文本的格式,这样就可以遍历了。到这里我们已经可以通过HttpClient和Jackson组件获取到了我们需要的信息,可以在应用中提供天气预报服务了,但是我们最开始使用的是一个城市代码,比如代表大连的101070201,这个数字是网站自己定义的,而没有其它任何实际含义(比如电话区号,行政代码等),那么要么我们在网站直接获得该城市的代码,否则就无法得到城市代码而去查询API了。其实网站也为我们获取城市代码提供了查询方法,如下:
访问http://m.weather.com.cn/data5/city.xml?level=0,(后面level参数可省略)得到一级列表(省、直辖市、自治区),结果用逗号隔开,id和城市名称使用竖线“|”隔开;结果示例如下:
01|北京,02|上海,03|天津,04|重庆,05|黑龙江,06|吉林,07|辽宁,08|内蒙古,09|河北,10|山西,11|陕西,12|山东,13|新疆,14|西藏,15|青海,16|甘肃,17|宁夏…
之后我们继续访问http://m.weather.com.cn/data5/city02.xml?level=1,(后面level参数可省略)得到二级列表。其中02是一级省市的id,结果格式和上一层相同,示例如下(河南):
1801|郑州,1802|安阳,1803|新乡,1804|许昌,1805|平顶山,1806|信阳,1807|南阳,1808|开封,1809|洛阳,1810|商丘,1811|焦作,1812|鹤壁,1813|濮阳,1814|周口,1815|漯河,1816|驻马店,1817|三门峡,1818|济源
继续访问http://m.weather.com.cn/data5/city1809.xml?level=3,(后面level参数可省略)得到后一级的id,是区域的id,示例如下(洛阳市):
180901|洛阳,180902|新安,180903|孟津,180904|宜阳,180905|洛宁,180906|伊川,180907|嵩县,180908|偃师,180909|栾川,180910|汝阳
继续访问http://m.weather.com.cn/data5/city180908.xml,获得偃师市的代码:180908|101180908,那么通过101180908就可以获得偃师市的天气预报。
知道这个规则后就可以在页面使用ajax方式请求地址获取到城市代码然后执行拿到天气预报,而在程序中,我们就需要一级一级的请求来获取代码了。
下面就展示一下这个根据字符串地址获取天气的程序:
package weather; import java.io.InputStream; import java.util.HashMap; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.lang.StringUtils; import org.codehaus.jackson.JsonFactory; import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonToken; import org.codehaus.jackson.map.MappingJsonFactory; public class Demo2 { public static void main(String[] args) throws Exception { String name = "河南洛阳偃师"; StringBuffer cityCode = new StringBuffer(); String provinceName = null;// 省份名称 String cityName = null;// 城市名称 String districtName = null;// 区县名称 if (name.length() >= 6) { provinceName = name.substring(0, 2); cityName = name.substring(2); districtName = name.substring(4); } else if (name.length() == 5) { provinceName = name.substring(0, 2); cityName = name.substring(2); districtName = ""; } else if (name.length() <= 4) { provinceName = name.substring(0, 2); cityName = ""; districtName = name.substring(2); } else { System.out.println("城市名称错误"); System.exit(0); } // 下面开始根据这三个名称来获取weather.com.cn的城市代码 HttpClient client = new HttpClient(); GetMethod get = new GetMethod("http://m.weather.com.cn/data5/city.xml");// 获取省份 String provinceStr = null; if (client.executeMethod(get) == HttpStatus.SC_OK) { provinceStr = get.getResponseBodyAsString(); } String[] provinceArray = provinceStr.split(","); String provinceCode = null; for (int i = 0; i < provinceArray.length; i++) {// 遍历省份 if (provinceArray[i].substring(3).indexOf(provinceName) != -1) { provinceCode = provinceArray[i].substring(0, 2); cityCode.append(provinceCode);// 获得省份编码 } } // 城市代码 if (Integer.parseInt(provinceCode) <= 4 || Integer.parseInt(provinceCode) >= 32) {// 直辖市和港澳台 get = new GetMethod("http://m.weather.com.cn/data5/city" + provinceCode + "01.xml"); if (client.executeMethod(get) == HttpStatus.SC_OK) { String[] districtArray = get.getResponseBodyAsString().split( ","); for (int i = 0; i < districtArray.length; i++) { if (districtName.indexOf(districtArray[i].substring(7)) != -1) { cityCode.append("01").append( districtArray[i].substring(4, 6));// 直辖市或港澳台代码获取结束,6位 } } if (cityCode.length() < 6) { cityCode.append("0101"); } } } else {// 省市 get = new GetMethod("http://m.weather.com.cn/data5/city" + provinceCode + ".xml"); String[] cityArray = null; if (client.executeMethod(get) == HttpStatus.SC_OK) { cityArray = get.getResponseBodyAsString().split(",");// 获取到了城市数组 } if (StringUtils.isEmpty(cityName)) {// 没有取到城市名 for (int i = 0; i < cityArray.length; i++) { if (districtName.indexOf(cityArray[i].substring(5)) != -1) { cityCode.append(cityArray[i].substring(2, 4)).append( "01");// 省直管地区代码获取结束,6位 } } } else if (StringUtils.isNotEmpty(cityName)) {// 取得了城市名 for (int i = 0; i < cityArray.length; i++) { if (cityName.indexOf(cityArray[i].substring(5)) != -1) { cityCode.append(cityArray[i].substring(2, 4)); } } get = new GetMethod("http://m.weather.com.cn/data5/city" + cityCode.toString() + ".xml");// 请求4位城市代码 String[] districtArray = null; if (client.executeMethod(get) == HttpStatus.SC_OK) { districtArray = get.getResponseBodyAsString().split(","); } for (int i = 0; i < districtArray.length; i++) { if (districtName.indexOf(districtArray[i].substring(7)) != -1) { cityCode.append(districtArray[i].substring(4, 6)); } } if (cityCode.toString().length() == 4) { cityCode.append("01"); } } } if (cityCode.length() == 6) { // 获取城市代码结束,获取天气页面代号 GetMethod weatherCodeGet = new GetMethod( "http://m.weather.com.cn/data5/city" + cityCode.toString() + ".xml"); String weatherCode = ""; if (client.executeMethod(weatherCodeGet) == HttpStatus.SC_OK) { weatherCode = weatherCodeGet.getResponseBodyAsString() .substring(7); } GetMethod weatherGet = new GetMethod( "http://m.weather.com.cn/data/" + weatherCode + ".html"); InputStream weatherInfo = null; if (client.executeMethod(weatherGet) == HttpStatus.SC_OK) { weatherInfo = weatherGet.getResponseBodyAsStream(); // HashMap<String, String> map = new HashMap<String, String> (); JsonFactory jsonFactory = new MappingJsonFactory(); JsonParser jsonParser = jsonFactory .createJsonParser(weatherInfo); // 跳到结果集的开始 jsonParser.nextToken(); while (jsonParser.nextToken() != JsonToken.END_OBJECT) { // 跳转到Value jsonParser.nextToken(); map.put(jsonParser.getCurrentName(), jsonParser.getText()); } // 封装VO,向页面传递数据 Weather todayWeather = new Weather(); // 当日数据 todayWeather.setCity(map.get("city")); todayWeather.setDate(map.get("date_y")); todayWeather.setLunarDate(map.get("date")); todayWeather.setWeek(map.get("week")); todayWeather.setFcTime(map.get("fchh")); todayWeather.setTemperature(map.get("temp1")); todayWeather.setWeather(map.get("weather1")); todayWeather.setWind(map.get("wind1")); System.out.println(todayWeather); } } else { System.out.println("没有获取到天气信息"); } } }
程序中对城市名称做了一点限制,直辖市等级为省,没有城市名,有城市名可以不用输入到区县,又如:
String name = "河南洛阳"; String name = "河南洛阳涧西";
这都是可以的,程序中对城市名称的处理可能不很准确,真实环境中这省市区这三个字段应该分别提供,截字符串可能会有偏差,本程序测试了大多数情况,是可行的。
本文系作者的实践探索,欢迎交流,希望对使用者有用。
1 楼
satikey
2010-11-25
学习了额,如果是我写的话 我会用 httpclient 4.01

2 楼
sarin
2010-11-25
satikey 写道
学习了额,如果是我写的话 我会用 httpclient 4.01

上一篇用的是第4版,这样就都兼顾到了。
3 楼
lqixv
2010-11-26
太棒了
写得相当不错,支持一下!!!

写得相当不错,支持一下!!!
4 楼
satikey
2010-11-26
sarin 写道
satikey 写道
学习了额,如果是我写的话 我会用 httpclient 4.01

上一篇用的是第4版,这样就都兼顾到了。
好吧,我没有仔细看你的博客内容。呵呵,我的博客才开张,里面也有一个HttpClient3.1写的实例,可以交流一下哦。我和我的公主大人共同维护者。
5 楼
SpreadDiaries
2010-11-26
jackson支持反射类的。参考 ObjectMapper 的 readValue
6 楼
sarin
2010-11-27
SpreadDiaries 写道
jackson支持反射类的。参考 ObjectMapper 的 readValue
有可以参考的示例吗?
7 楼
yuhe
2010-11-29
呵呵,感谢楼主。
杰克逊,
杰克逊,

8 楼
newvirus
2010-12-02
高手啊 学习收藏啦
9 楼
lqixv
2010-12-13
返回的json的各个参数,在哪里有注释?
还有,我想找其中的“空气污浊指数”,找不到。你知道是哪个吗?
还有,我想找其中的“空气污浊指数”,找不到。你知道是哪个吗?
10 楼
sarin
2010-12-13
lqixv 写道
返回的json的各个参数,在哪里有注释?
还有,我想找其中的“空气污浊指数”,找不到。你知道是哪个吗?
还有,我想找其中的“空气污浊指数”,找不到。你知道是哪个吗?
这个只能参考官网页面里的信息和json的信息比对来确定了。
11 楼
JavaLanguageFun
2010-12-14
写得相当不错,支持一下!!!
12 楼
lenj
2010-12-23
能否提供下JAR包?
还有当省份的名字为3个字 市的名字为很多字的时候就不通用了
1
还有当省份的名字为3个字 市的名字为很多字的时候就不通用了
1
13 楼
sarin
2010-12-23
lenj 写道
能否提供下JAR包?
还有当省份的名字为3个字 市的名字为很多字的时候就不通用了
1
还有当省份的名字为3个字 市的名字为很多字的时候就不通用了
1
这里就是之前要处理的地方了,JAR包请参考Maven的设置。
14 楼
niuky
2011-01-05
sarin 写道
lqixv 写道
返回的json的各个参数,在哪里有注释?
还有,我想找其中的“空气污浊指数”,找不到。你知道是哪个吗?
还有,我想找其中的“空气污浊指数”,找不到。你知道是哪个吗?
这个只能参考官网页面里的信息和json的信息比对来确定了。
这个官网的json说明在哪呢?》
15 楼
sarin
2011-01-05
niuky 写道
sarin 写道
lqixv 写道
返回的json的各个参数,在哪里有注释?
还有,我想找其中的“空气污浊指数”,找不到。你知道是哪个吗?
还有,我想找其中的“空气污浊指数”,找不到。你知道是哪个吗?
这个只能参考官网页面里的信息和json的信息比对来确定了。
这个官网的json说明在哪呢?》
官网没有对json的说明,只能比对字段信息然后确定含义。
16 楼
lshoo
2011-03-26
学习了,用httpclient4改写一下。
17 楼
ariestiger
2011-08-02
{"weatherinfo":{
"city":"上海",
"city_en":"shanghai",
"date_y":"2011年8月2日",
"date":"辛卯年",
"week":"星期二",
"fchh":"08",
"cityid":"101020100",
"temp1":"34℃~28℃",
"temp2":"33℃~27℃","temp3":"33℃~26℃","temp4":"31℃~25℃","temp5":"30℃~25℃","temp6":"30℃~26℃","tempF1":"93.2ㄈ~82.4ㄈ","tempF2":"91.4ㄈ~80.6ㄈ","tempF3":"91.4ㄈ~78.8ㄈ","tempF4":"87.8ㄈ~77ㄈ","tempF5":"86ㄈ~77ㄈ","tempF6":"86ㄈ~78.8ㄈ","weather1":"雷阵雨转多云","weather2":"雷阵雨转多云","weather3":"多云","weather4":"雷阵雨","weather5":"雷阵雨转阵雨","weather6":"雷阵雨转多云","img1":"4","img2":"1","img3":"4","img4":"1","img5":"1","img6":"99","img7":"4","img8":"99","img9":"4","img10":"3","img11":"4","img12":"1","img_single":"4","img_title1":"雷阵雨","img_title2":"多云","img_title3":"雷阵雨","img_title4":"多云","img_title5":"多云","img_title6":"多云","img_title7":"雷阵雨","img_title8":"雷阵雨","img_title9":"雷阵雨","img_title10":"阵雨","img_title11":"雷阵雨","img_title12":"多云","img_title_single":"雷阵雨","wind1":"东南风3-4级","wind2":"东南风3-4级","wind3":"东风3-4级转东北风4-5级","wind4":"东北风3-4级转北风4-5级","wind5":"北风5-6级","wind6":"西北风5-6级","fx1":"东南风","fx2":"东南风","fl1":"3-4级","fl2":"3-4级","fl3":"3-4级转4-5级","fl4":"3-4级转4-5级","fl5":"5-6级","fl6":"5-6级","index":"炎热","index_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index48":"炎热","index48_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index_uv":"中等","index48_uv":"中等","index_xc":"不宜","index_tr":"一般","index_co":"较不舒适","st1":"31","st2":"26","st3":"30","st4":"24","st5":"32","st6":"24","index_cl":"较不宜","index_ls":"不宜"}}
算了, 我懒得整这个格式了,这什么temp1,temp2,img1,img2,是今天,明天,后面,,,,之后总共六天的温度,图标,index_uv是紫外线强度,这是用的英文缩写,index_xc是洗车指数,这是拼音缩写,index_tr是旅游指数,travell,英文缩写,index_co是comfortable,舒适度指数,英文缩写,index_cl是晨练指数,拼音缩写,index_ls是晾晒指数,拼音缩写,我郁了个闷的
"city":"上海",
"city_en":"shanghai",
"date_y":"2011年8月2日",
"date":"辛卯年",
"week":"星期二",
"fchh":"08",
"cityid":"101020100",
"temp1":"34℃~28℃",
"temp2":"33℃~27℃","temp3":"33℃~26℃","temp4":"31℃~25℃","temp5":"30℃~25℃","temp6":"30℃~26℃","tempF1":"93.2ㄈ~82.4ㄈ","tempF2":"91.4ㄈ~80.6ㄈ","tempF3":"91.4ㄈ~78.8ㄈ","tempF4":"87.8ㄈ~77ㄈ","tempF5":"86ㄈ~77ㄈ","tempF6":"86ㄈ~78.8ㄈ","weather1":"雷阵雨转多云","weather2":"雷阵雨转多云","weather3":"多云","weather4":"雷阵雨","weather5":"雷阵雨转阵雨","weather6":"雷阵雨转多云","img1":"4","img2":"1","img3":"4","img4":"1","img5":"1","img6":"99","img7":"4","img8":"99","img9":"4","img10":"3","img11":"4","img12":"1","img_single":"4","img_title1":"雷阵雨","img_title2":"多云","img_title3":"雷阵雨","img_title4":"多云","img_title5":"多云","img_title6":"多云","img_title7":"雷阵雨","img_title8":"雷阵雨","img_title9":"雷阵雨","img_title10":"阵雨","img_title11":"雷阵雨","img_title12":"多云","img_title_single":"雷阵雨","wind1":"东南风3-4级","wind2":"东南风3-4级","wind3":"东风3-4级转东北风4-5级","wind4":"东北风3-4级转北风4-5级","wind5":"北风5-6级","wind6":"西北风5-6级","fx1":"东南风","fx2":"东南风","fl1":"3-4级","fl2":"3-4级","fl3":"3-4级转4-5级","fl4":"3-4级转4-5级","fl5":"5-6级","fl6":"5-6级","index":"炎热","index_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index48":"炎热","index48_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index_uv":"中等","index48_uv":"中等","index_xc":"不宜","index_tr":"一般","index_co":"较不舒适","st1":"31","st2":"26","st3":"30","st4":"24","st5":"32","st6":"24","index_cl":"较不宜","index_ls":"不宜"}}
算了, 我懒得整这个格式了,这什么temp1,temp2,img1,img2,是今天,明天,后面,,,,之后总共六天的温度,图标,index_uv是紫外线强度,这是用的英文缩写,index_xc是洗车指数,这是拼音缩写,index_tr是旅游指数,travell,英文缩写,index_co是comfortable,舒适度指数,英文缩写,index_cl是晨练指数,拼音缩写,index_ls是晾晒指数,拼音缩写,我郁了个闷的
18 楼
sarin
2011-08-02
ariestiger 写道
{"weatherinfo":{
"city":"上海",
"city_en":"shanghai",
"date_y":"2011年8月2日",
"date":"辛卯年",
"week":"星期二",
"fchh":"08",
"cityid":"101020100",
"temp1":"34℃~28℃",
"temp2":"33℃~27℃","temp3":"33℃~26℃","temp4":"31℃~25℃","temp5":"30℃~25℃","temp6":"30℃~26℃","tempF1":"93.2ㄈ~82.4ㄈ","tempF2":"91.4ㄈ~80.6ㄈ","tempF3":"91.4ㄈ~78.8ㄈ","tempF4":"87.8ㄈ~77ㄈ","tempF5":"86ㄈ~77ㄈ","tempF6":"86ㄈ~78.8ㄈ","weather1":"雷阵雨转多云","weather2":"雷阵雨转多云","weather3":"多云","weather4":"雷阵雨","weather5":"雷阵雨转阵雨","weather6":"雷阵雨转多云","img1":"4","img2":"1","img3":"4","img4":"1","img5":"1","img6":"99","img7":"4","img8":"99","img9":"4","img10":"3","img11":"4","img12":"1","img_single":"4","img_title1":"雷阵雨","img_title2":"多云","img_title3":"雷阵雨","img_title4":"多云","img_title5":"多云","img_title6":"多云","img_title7":"雷阵雨","img_title8":"雷阵雨","img_title9":"雷阵雨","img_title10":"阵雨","img_title11":"雷阵雨","img_title12":"多云","img_title_single":"雷阵雨","wind1":"东南风3-4级","wind2":"东南风3-4级","wind3":"东风3-4级转东北风4-5级","wind4":"东北风3-4级转北风4-5级","wind5":"北风5-6级","wind6":"西北风5-6级","fx1":"东南风","fx2":"东南风","fl1":"3-4级","fl2":"3-4级","fl3":"3-4级转4-5级","fl4":"3-4级转4-5级","fl5":"5-6级","fl6":"5-6级","index":"炎热","index_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index48":"炎热","index48_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index_uv":"中等","index48_uv":"中等","index_xc":"不宜","index_tr":"一般","index_co":"较不舒适","st1":"31","st2":"26","st3":"30","st4":"24","st5":"32","st6":"24","index_cl":"较不宜","index_ls":"不宜"}}
算了, 我懒得整这个格式了,这什么temp1,temp2,img1,img2,是今天,明天,后面,,,,之后总共六天的温度,图标,index_uv是紫外线强度,这是用的英文缩写,index_xc是洗车指数,这是拼音缩写,index_tr是旅游指数,travell,英文缩写,index_co是comfortable,舒适度指数,英文缩写,index_cl是晨练指数,拼音缩写,index_ls是晾晒指数,拼音缩写,我郁了个闷的
"city":"上海",
"city_en":"shanghai",
"date_y":"2011年8月2日",
"date":"辛卯年",
"week":"星期二",
"fchh":"08",
"cityid":"101020100",
"temp1":"34℃~28℃",
"temp2":"33℃~27℃","temp3":"33℃~26℃","temp4":"31℃~25℃","temp5":"30℃~25℃","temp6":"30℃~26℃","tempF1":"93.2ㄈ~82.4ㄈ","tempF2":"91.4ㄈ~80.6ㄈ","tempF3":"91.4ㄈ~78.8ㄈ","tempF4":"87.8ㄈ~77ㄈ","tempF5":"86ㄈ~77ㄈ","tempF6":"86ㄈ~78.8ㄈ","weather1":"雷阵雨转多云","weather2":"雷阵雨转多云","weather3":"多云","weather4":"雷阵雨","weather5":"雷阵雨转阵雨","weather6":"雷阵雨转多云","img1":"4","img2":"1","img3":"4","img4":"1","img5":"1","img6":"99","img7":"4","img8":"99","img9":"4","img10":"3","img11":"4","img12":"1","img_single":"4","img_title1":"雷阵雨","img_title2":"多云","img_title3":"雷阵雨","img_title4":"多云","img_title5":"多云","img_title6":"多云","img_title7":"雷阵雨","img_title8":"雷阵雨","img_title9":"雷阵雨","img_title10":"阵雨","img_title11":"雷阵雨","img_title12":"多云","img_title_single":"雷阵雨","wind1":"东南风3-4级","wind2":"东南风3-4级","wind3":"东风3-4级转东北风4-5级","wind4":"东北风3-4级转北风4-5级","wind5":"北风5-6级","wind6":"西北风5-6级","fx1":"东南风","fx2":"东南风","fl1":"3-4级","fl2":"3-4级","fl3":"3-4级转4-5级","fl4":"3-4级转4-5级","fl5":"5-6级","fl6":"5-6级","index":"炎热","index_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index48":"炎热","index48_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index_uv":"中等","index48_uv":"中等","index_xc":"不宜","index_tr":"一般","index_co":"较不舒适","st1":"31","st2":"26","st3":"30","st4":"24","st5":"32","st6":"24","index_cl":"较不宜","index_ls":"不宜"}}
算了, 我懒得整这个格式了,这什么temp1,temp2,img1,img2,是今天,明天,后面,,,,之后总共六天的温度,图标,index_uv是紫外线强度,这是用的英文缩写,index_xc是洗车指数,这是拼音缩写,index_tr是旅游指数,travell,英文缩写,index_co是comfortable,舒适度指数,英文缩写,index_cl是晨练指数,拼音缩写,index_ls是晾晒指数,拼音缩写,我郁了个闷的
这都是网站直接定义好的,可以直接使用
19 楼
lindakun
2012-03-01
感谢楼主~~~
20 楼
yu_duo
2012-09-24
写的好详细~~,虽然我看的晚了,但是很受用~谢谢~~