首页 > 其他分享 >根据名称,获取省、市、区,编码

根据名称,获取省、市、区,编码

时间:2024-12-10 10:54:38浏览次数:4  
标签:编码 code name area 市辖区 获取 名称 import String

省市JSON

[{
	"name": "北京市",
	"code": "110000",
	"city": [{
		"name": "市辖区",
		"code": "110100",
		"area": [{
			"name": "东城区",
			"code": "110101"
		},
		{
			"name": "西城区",
			"code": "110102"
		},
		{
			"name": "朝阳区",
			"code": "110105"
		},
		{
			"name": "丰台区",
			"code": "110106"
		},
		{
			"name": "石景山区",
			"code": "110107"
		},
		{
			"name": "海淀区",
			"code": "110108"
		},
		{
			"name": "门头沟区",
			"code": "110109"
		},
		{
			"name": "房山区",
			"code": "110111"
		},
		{
			"name": "通州区",
			"code": "110112"
		},
		{
			"name": "顺义区",
			"code": "110113"
		},
		{
			"name": "昌平区",
			"code": "110114"
		},
		{
			"name": "大兴区",
			"code": "110115"
		},
		{
			"name": "怀柔区",
			"code": "110116"
		},
		{
			"name": "平谷区",
			"code": "110117"
		},
		{
			"name": "密云区",
			"code": "110118"
		},
		{
			"name": "延庆区",
			"code": "110119"
		}]
	}]
},
{
	"name": "江苏省",
	"code": "320000",
	"city": [{
		"name": "南京市",
		"code": "320100",
		"area": [{
			"name": "市辖区",
			"code": "320101"
		},
		{
			"name": "玄武区",
			"code": "320102"
		},
		{
			"name": "秦淮区",
			"code": "320104"
		},
		{
			"name": "建邺区",
			"code": "320105"
		},
		{
			"name": "鼓楼区",
			"code": "320106"
		},
		{
			"name": "浦口区",
			"code": "320111"
		},
		{
			"name": "栖霞区",
			"code": "320113"
		},
		{
			"name": "雨花台区",
			"code": "320114"
		},
		{
			"name": "江宁区",
			"code": "320115"
		},
		{
			"name": "六合区",
			"code": "320116"
		},
		{
			"name": "溧水区",
			"code": "320117"
		},
		{
			"name": "高淳区",
			"code": "320118"
		}]
	},
	{
		"name": "无锡市",
		"code": "320200",
		"area": [{
			"name": "市辖区",
			"code": "320201"
		},
		{
			"name": "锡山区",
			"code": "320205"
		},
		{
			"name": "惠山区",
			"code": "320206"
		},
		{
			"name": "滨湖区",
			"code": "320211"
		},
		{
			"name": "梁溪区",
			"code": "320213"
		},
		{
			"name": "新吴区",
			"code": "320214"
		},
		{
			"name": "江阴市",
			"code": "320281"
		},
		{
			"name": "宜兴市",
			"code": "320282"
		}]
	},
	{
		"name": "徐州市",
		"code": "320300",
		"area": [{
			"name": "市辖区",
			"code": "320301"
		},
		{
			"name": "鼓楼区",
			"code": "320302"
		},
		{
			"name": "云龙区",
			"code": "320303"
		},
		{
			"name": "贾汪区",
			"code": "320305"
		},
		{
			"name": "泉山区",
			"code": "320311"
		},
		{
			"name": "铜山区",
			"code": "320312"
		},
		{
			"name": "丰县",
			"code": "320321"
		},
		{
			"name": "沛县",
			"code": "320322"
		},
		{
			"name": "睢宁县",
			"code": "320324"
		},
		{
			"name": "新沂市",
			"code": "320381"
		},
		{
			"name": "邳州市",
			"code": "320382"
		}]
	},
	{
		"name": "常州市",
		"code": "320400",
		"area": [{
			"name": "市辖区",
			"code": "320401"
		},
		{
			"name": "天宁区",
			"code": "320402"
		},
		{
			"name": "钟楼区",
			"code": "320404"
		},
		{
			"name": "新北区",
			"code": "320411"
		},
		{
			"name": "武进区",
			"code": "320412"
		},
		{
			"name": "金坛区",
			"code": "320413"
		},
		{
			"name": "溧阳市",
			"code": "320481"
		}]
	},
	{
		"name": "苏州市",
		"code": "320500",
		"area": [{
			"name": "市辖区",
			"code": "320501"
		},
		{
			"name": "虎丘区",
			"code": "320505"
		},
		{
			"name": "吴中区",
			"code": "320506"
		},
		{
			"name": "相城区",
			"code": "320507"
		},
		{
			"name": "姑苏区",
			"code": "320508"
		},
		{
			"name": "吴江区",
			"code": "320509"
		},
		{
			"name": "常熟市",
			"code": "320581"
		},
		{
			"name": "张家港市",
			"code": "320582"
		},
		{
			"name": "昆山市",
			"code": "320583"
		},
		{
			"name": "太仓市",
			"code": "320585"
		}]
	},
	{
		"name": "南通市",
		"code": "320600",
		"area": [{
			"name": "市辖区",
			"code": "320601"
		},
		{
			"name": "崇川区",
			"code": "320602"
		},
		{
			"name": "港闸区",
			"code": "320611"
		},
		{
			"name": "通州区",
			"code": "320612"
		},
		{
			"name": "海安县",
			"code": "320621"
		},
		{
			"name": "如东县",
			"code": "320623"
		},
		{
			"name": "启东市",
			"code": "320681"
		},
		{
			"name": "如皋市",
			"code": "320682"
		},
		{
			"name": "海门市",
			"code": "320684"
		}]
	},
	{
		"name": "连云港市",
		"code": "320700",
		"area": [{
			"name": "市辖区",
			"code": "320701"
		},
		{
			"name": "连云区",
			"code": "320703"
		},
		{
			"name": "海州区",
			"code": "320706"
		},
		{
			"name": "赣榆区",
			"code": "320707"
		},
		{
			"name": "东海县",
			"code": "320722"
		},
		{
			"name": "灌云县",
			"code": "320723"
		},
		{
			"name": "灌南县",
			"code": "320724"
		}]
	},
	{
		"name": "淮安市",
		"code": "320800",
		"area": [{
			"name": "市辖区",
			"code": "320801"
		},
		{
			"name": "淮安区",
			"code": "320803"
		},
		{
			"name": "淮阴区",
			"code": "320804"
		},
		{
			"name": "清江浦区",
			"code": "320812"
		},
		{
			"name": "洪泽区",
			"code": "320813"
		},
		{
			"name": "涟水县",
			"code": "320826"
		},
		{
			"name": "盱眙县",
			"code": "320830"
		},
		{
			"name": "金湖县",
			"code": "320831"
		}]
	},
	{
		"name": "盐城市",
		"code": "320900",
		"area": [{
			"name": "市辖区",
			"code": "320901"
		},
		{
			"name": "亭湖区",
			"code": "320902"
		},
		{
			"name": "盐都区",
			"code": "320903"
		},
		{
			"name": "大丰区",
			"code": "320904"
		},
		{
			"name": "响水县",
			"code": "320921"
		},
		{
			"name": "滨海县",
			"code": "320922"
		},
		{
			"name": "阜宁县",
			"code": "320923"
		},
		{
			"name": "射阳县",
			"code": "320924"
		},
		{
			"name": "建湖县",
			"code": "320925"
		},
		{
			"name": "东台市",
			"code": "320981"
		}]
	},
	{
		"name": "扬州市",
		"code": "321000",
		"area": [{
			"name": "市辖区",
			"code": "321001"
		},
		{
			"name": "广陵区",
			"code": "321002"
		},
		{
			"name": "邗江区",
			"code": "321003"
		},
		{
			"name": "江都区",
			"code": "321012"
		},
		{
			"name": "宝应县",
			"code": "321023"
		},
		{
			"name": "仪征市",
			"code": "321081"
		},
		{
			"name": "高邮市",
			"code": "321084"
		}]
	},
	{
		"name": "镇江市",
		"code": "321100",
		"area": [{
			"name": "市辖区",
			"code": "321101"
		},
		{
			"name": "京口区",
			"code": "321102"
		},
		{
			"name": "润州区",
			"code": "321111"
		},
		{
			"name": "丹徒区",
			"code": "321112"
		},
		{
			"name": "丹阳市",
			"code": "321181"
		},
		{
			"name": "扬中市",
			"code": "321182"
		},
		{
			"name": "句容市",
			"code": "321183"
		}]
	},
	{
		"name": "泰州市",
		"code": "321200",
		"area": [{
			"name": "市辖区",
			"code": "321201"
		},
		{
			"name": "海陵区",
			"code": "321202"
		},
		{
			"name": "高港区",
			"code": "321203"
		},
		{
			"name": "姜堰区",
			"code": "321204"
		},
		{
			"name": "兴化市",
			"code": "321281"
		},
		{
			"name": "靖江市",
			"code": "321282"
		},
		{
			"name": "泰兴市",
			"code": "321283"
		}]
	},
	{
		"name": "宿迁市",
		"code": "321300",
		"area": [{
			"name": "市辖区",
			"code": "321301"
		},
		{
			"name": "宿城区",
			"code": "321302"
		},
		{
			"name": "宿豫区",
			"code": "321311"
		},
		{
			"name": "沭阳县",
			"code": "321322"
		},
		{
			"name": "泗阳县",
			"code": "321323"
		},
		{
			"name": "泗洪县",
			"code": "321324"
		}]
	}]
},
]

AdministrativeDivisionUtil

package com.vipsoft.base.util;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import org.aspectj.util.FileUtil;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Component
public class AdministrativeDivisionUtil {

    private String cityJsonPath = "/config/city_code_cn.json";

    public String getProvinceCode(String provinceName) {
        try {
            String jsonPath = this.getClass().getResource(cityJsonPath).getPath();
            String jsonString = FileUtil.readAsString(new File(jsonPath));
            List<Map<String, String>> map = JSON.parseObject(jsonString, List.class);
            for (Map<String, String> province : map) {
                if (province.get("name").contains(provinceName)) {
                    return province.get("code");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    public String getCityCode(String provinceName, String cityName) {
        try {
            String jsonPath = this.getClass().getResource(cityJsonPath).getPath();
            String jsonString = FileUtil.readAsString(new File(jsonPath));
            List<Map<String, String>> map = JSON.parseObject(jsonString, List.class);
            String code = "";
            for (Map<String, String> province : map) {
                if (!province.get("name").contains(provinceName)) {
                    continue;
                }
                Object cityJson = province.get("city");
                if (cityJson != null) {
                    String jsonStr = JSON.toJSONString(cityJson);
                    JSONArray jsonArray = JSON.parseArray(jsonStr);
                    List<Map> javaList = jsonArray.toJavaList(Map.class);
                    for (Map<String, String> city : javaList) {
                        if (city.get("name").contains(cityName)) {
                            return city.get("code");
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

}

标签:编码,code,name,area,市辖区,获取,名称,import,String
From: https://www.cnblogs.com/vipsoft/p/18596875

相关文章

  • OpenFeign请求头丢失问题!OpenFeign同步调用、异步调用获取不到请求头问题!
    OpenFeign请求头丢失问题!OpenFeign同步调用、异步调用获取不到请求头问题!前言:一般SpringBoot项目中,都会有一个鉴权的拦截器或者过滤器,例如这样:@BeanpublicHandlerInterceptorauthInterceptor(){returnnewHandlerInterceptor(){@Override......
  • mysql 256byte可以存多少汉字,字符编码length,char_length函数
    mysql256byte可以存多少汉字,字符编码length,char_length函数在MySQL中,UTF-8编码下,每个汉字至少占用3个字节。因此,256字节可以存储的汉字数量为:(256字节)/(3字节/汉字)=85.3汉字由于UTF-8编码中,对于单字节的字符、双字节字符和三字节字符有不同的编码方式,实际使用中可能不能......
  • 企业如何构建自己的 AI 编码能力
    引言随着大型语言模型(LLMs)的兴起,如腾讯云AI代码助手和GitHubCopilot等工具已经开始改变开发者的工作方式。然而,这些工具大多基于公开数据训练,对于企业内部的私域数据和特定需求,其适应性仍有局限。因此,如何将这些工具与企业自身的私域数据相结合,构建起企业独特的AI编码能力......
  • 编码
    编码通信领域常用编码脉冲类似于人的脉搏,主要特性参数有波形幅度和重复频率电话拨号编码1-9分别使用1-9个脉冲,0则表示使用10个脉冲Morse编码(摩斯电码)最多6位也可以使用01串表示敲击码使用点击声音来命名编码TapCode123451ABC/KDE2FGH......
  • 违规抽烟识别智慧矿山一体机未戴安全帽识别:网络摄像机中的音频及音频编码阐述
    在现代网络摄像机的设计中,音频功能已成为一个不可或缺的组成部分,它不仅增强了监控系统的能力,还为用户提供了更丰富的现场信息。音频功能使得网络摄像机能够捕捉到环境中的声音,从而在安全监控、远程通信以及其他多种应用中发挥重要作用。本文将详细探讨网络摄像机中的音频功能及其......
  • 获取进程或线程级别的iodelay的方法
    一、背景内核里为每个应用程序(线程或进程颗粒度)因为IO操作所导致的线程的睡眠有一项专门的统计,叫iodelay,为什么叫这个名字,因为我们用pidstat查看具体进程I/O的时延时,是用的这个名字,如下红色框图:pidstat-d显示出来的iodelay是以userHZ为单位的。关于现有工具也就是通过pids......
  • Ruby 中文编码
    用Ruby输出"Hello,World!",英文没有问题,但是如果你输出中文字符"你好,世界"就有可能会碰到中文编码问题。Ruby文件中如果未指定编码,在执行过程会出现报错:#!/usr/bin/ruby-wputs"你好,世界!";以上程序执行输出结果为:invalidmultibytechar(US-ASCII)以上出错信息显......
  • 使用Python开发获取商品销量详情API接口?(一篇文章全学会)
    在现代软件开发中,API(应用程序编程接口)已成为不同软件间交互的桥梁。尤其在电商领域,API接口使得开发者能够访问和操作电商平台上的数据,如商品详情、用户评价、订单信息等。本文将详细介绍如何使用Python开发一个获取商品销量详情的API接口。一、API接口概述API(ApplicationPro......
  • js获取某个月的星期每周的集合
    先看返回的数据格式  //获取某个月的星期每周的集合,date所在的月份的functiongetWeeksInMonth(date){letyear=date.getFullYear()letmonth=date.getMonth()+1;constfirstDayOfMonth=newDate(year,month-1,1);constlastDayOfMonth=newDa......
  • 你知道什么是硬编码吗?什么时候会用到硬编码呢?
    在前端开发中,硬编码(Hardcoding)指的是直接将数据值嵌入到源代码中,而不是从外部来源(例如数据库、配置文件或API)获取。这意味着值在代码中是固定的,如果需要更改,必须修改代码本身。以下是一些在前端开发中可能使用硬编码的情况,以及它们的优缺点:何时会用到硬编码?原型设计和快速开......