本篇内容介绍了“如何使用聚合数据实现Json解析全国市县区按汉字首字母排序”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
创新互联公司是一家专注于成都做网站、成都网站制作与策划设计,抚顺网站建设哪家好?创新互联公司做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:抚顺等地区。抚顺做网站价格咨询: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 Listlist_district = new ArrayList (); public static void main(String[] args) { URL url; try { url = new URL( "http://v.juhe.cn/postcode/pcd?dtype=json&key=9da.......");/需要自己申请 聚合数据的 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 “如何使用聚合数据实现Json解析全国市县区按汉字首字母排序”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
文章标题:如何使用聚合数据实现Json解析全国市县区按汉字首字母排序
当前网址:http://www.cdkjz.cn/article/iiedjo.html