本篇內(nèi)容介紹了“如何使用聚合數(shù)據(jù)實(shí)現(xiàn)Json解析全國(guó)市縣區(qū)按漢字首字母排序”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)公司是一家專(zhuān)注于成都做網(wǎng)站、成都網(wǎng)站制作與策劃設(shè)計(jì),撫順網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專(zhuān)注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專(zhuān)業(yè)建站公司;建站業(yè)務(wù)涵蓋:撫順等地區(qū)。撫順做網(wǎng)站價(jià)格咨詢:028-86922220
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.text.Collator; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Locale; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class Test_1 { private static String result_info = ""; static List<String> list_district = new ArrayList<String>(); public static void main(String[] args) { URL url; try { url = new URL( "http://v.juhe.cn/postcode/pcd?dtype=json&key=9da.......");/需要自己申請(qǐng) 聚合數(shù)據(jù)的 apikey HttpURLConnection urlcon = (HttpURLConnection) url.openConnection(); urlcon.connect(); // 獲取連接 InputStream is = urlcon.getInputStream(); BufferedReader buffer = new BufferedReader(new InputStreamReader( is, "utf-8")); StringBuffer bs = new StringBuffer(); String linputline = null; while ((linputline = buffer.readLine()) != null) { result_info += linputline + "\n"; } // System.out.println(result_info);///所有信息不用輸出 if (!result_info.equals("")) { JSONObject dataJson = JSONObject.fromObject(result_info); System.out.println(dataJson.getString("reason")); // JSONObject result_province = // dataJson.getJSONObject("result"); for (int j = 0; j < 31; j++) { JSONArray result_province_array = dataJson .getJSONArray("result"); String province = result_province_array.getJSONObject(j) .getString("province"); // System.out.println(j + 1 + ": " + province); list_district.add(province); JSONArray result_province_city_array = result_province_array .getJSONObject(j).getJSONArray("city"); for (int k = 0; k < result_province_city_array.size(); k++) { String city = result_province_city_array.getJSONObject( k).getString("city"); String city_id = result_province_city_array .getJSONObject(k).getString("id"); // // System.out.println(j + 1 + city_id + ": " + province // + ":" + city); list_district.add(province + " " + city); JSONArray result_province_city_district_array = result_province_city_array .getJSONObject(k).getJSONArray("district"); for (int m = 0; m < result_province_city_district_array .size(); m++) { String district_id = result_province_city_district_array .getJSONObject(m).getString("id"); String district = result_province_city_district_array .getJSONObject(m).getString("district"); // System.out.println(j + 1 + city_id + district_id // + ": " + province + " " + city + " " // + district); list_district.add(province + " " + city + " " + district); }// /for m }// /for k }// /for j }//if String[] str_district = new String[list_district.size()]; for(int n=0;n<list_district.size();n++){ str_district[n]=list_district.get(n); //System.out.println(str_district[n]); } Comparator c= Collator.getInstance(Locale.CHINA); Arrays.sort(str_district, c); for(int p=0;p<str_district.length;p++){ System.out.println(str_district[p]); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }///main }
“如何使用聚合數(shù)據(jù)實(shí)現(xiàn)Json解析全國(guó)市縣區(qū)按漢字首字母排序”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
網(wǎng)站欄目:如何使用聚合數(shù)據(jù)實(shí)現(xiàn)Json解析全國(guó)市縣區(qū)按漢字首字母排序
網(wǎng)站路徑:http://jinyejixie.com/article20/iiedjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站導(dǎo)航、商城網(wǎng)站、網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)