中国天气网省市区JSON列表

    xiaoxiao2021-03-25  22

    完整下载地址: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); }

    转载请注明原文地址: https://ju.6miu.com/read-300130.html

    最新回复(0)