中国天气网省市区JSON列表

完整下载地址:http://download.csdn.net/detail/u013183495/9756433  通过解析html拿到。


String u = "china.html";

public static void parserCity(String url){
		String web = sendGet("http://sq.weather.com.cn/manage/citylist/"+url, null);
		Document doc = Jsoup.parse(web);
		Elements list = doc.getElementsByClass("citylist");
		Element c = list.get(0);
		Elements a = c.getElementsByTag("a");
		JSONArray arr = new JSONArray();
		for(Element e :a){
			JSONObject province = new JSONObject();
			province.accumulate("provinceName", e.ownText());
			String ID =  e.attr("href");
			ID = ID.substring(ID.lastIndexOf("=")+1,ID.length());
			province.accumulate("id",ID);
			//http://sq.weather.com.cn/manage/citylist/city3jdata/provshi/10101.html
			String webSub = sendGet("http://sq.weather.com.cn/manage/citylist/city3jdata/provshi/"+ID+".html", null);
			
			JSONObject cc = JSONObject.fromObject(webSub);
			if(Integer.valueOf(ID)>10104){
				 JSONArray cccc = new JSONArray();
					String key = null;
					Iterator i= cc.keys();
					while(i.hasNext()){
						key = (String)i.next();
						//System.out.println(key);
						JSONObject dis = new JSONObject();
						dis.accumulate("cityName", cc.getString(key));
						String cid = ID+key;
						dis.accumulate("cityId",cid );
						String ddd = sendGet("http://sq.weather.com.cn/manage/citylist/city3jdata/station/"+cid+".html", null);
						
						JSONObject ccD = JSONObject.fromObject(ddd);
						Iterator d = ccD.keys();
						JSONArray districts = new JSONArray();
						while(d.hasNext()){
							String keySub = (String)d.next();
							JSONObject sm = new JSONObject();
							sm.accumulate("districtName", ccD.getString(keySub));
							sm.accumulate("districtId", cid+(keySub));
							districts.add(sm);
						}
						dis.accumulate("districtList", districts);
						cccc.add(dis); 
					}
					province.accumulate("cityList", cccc);
			}else{
				JSONObject ccD = JSONObject.fromObject(webSub);
				Iterator d = ccD.keys();
				JSONArray dLsi = new JSONArray();
				while(d.hasNext()){
					String keySub = (String)d.next();
					JSONObject sm = new JSONObject();
					sm.accumulate("cityName", ccD.getString(keySub));
					sm.accumulate("cityId", ID+(keySub)+"00");
					dLsi.add(sm);
					
				}
				province.accumulate("cityList", dLsi);
			}
			arr.add(province);
			
		}
		System.out.println(arr); 
	}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kevin4ch

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值