In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to use aggregate data to achieve Json analysis of cities, counties and districts across the country according to the first letter of Chinese characters". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
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 list_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.......");/ needs to apply for apikey HttpURLConnection urlcon = (HttpURLConnection) url.openConnection (); urlcon.connect ()) / / get connection 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) / / all information need not be output 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) JSONArray ("result") {JSONArray result_province_array = dataJson .getJSONArray 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 (); knight +) {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 () String district_id +) {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 nasty 0ntern
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.