Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use aggregate data to realize Json parsing sorting of cities, counties and districts according to the first letter of Chinese characters

Shulou Source: shulou.com Published: 2022-06-03 05:54:50 10月01日 Update

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

Tags: Data national alphabet city and county Chinese characters ranking content more knowledge output practicality achievement next no use information dilemma reality situation article case Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei MariaDB Shulou Information Xiaomi