精华内容
下载资源
问答
  • output.json

    2018-07-07 14:23:56
    地区选择json地区选择json地区选择json地区选择json
  •  在做H5开发过程中,地区选择的基础数据产品经理不知从哪里哪来了一些SQL,而这个数据其实很难会变,存储在后台的DB或者缓存中,好像没有必要,于是得想办法把它转成json串保存到文件中,请求时直接请求这个JSON串...

      在做H5开发过程中,地区选择的基础数据产品经理不知从哪里哪来了一些SQL,而这个数据其实很难会变,存储在后台的DB或者缓存中,好像没有必要,于是得想办法把它转成json串保存到文件中,请求时直接请求这个JSON串文件即可。

    基础SQL:

    DROP TABLE IF EXISTS Province;
    DROP TABLE IF EXISTS City;
    DROP TABLE IF EXISTS District;
    
    CREATE TABLE Province (Id int,
    	Name varchar(50) ,
    	orderid int 
    )row_format=dynamic engine=innodb default charset utf8;
    insert into Province values('1','北京','0'); 
    insert into Province values('2','天津','0');
    
    CREATE TABLE City(
    	Id int ,
    	ProvinceId int,
    	Name varchar(50),
    	AreaCode varchar(50)
    )row_format=dynamic engine=innodb default charset utf8;
    
    insert into City values('1','1','北京市','010'); 
    insert into City values('2','2','天津市','022'); 
    insert into City values('3','3','石家庄市','0311'); 
    insert into City values('4','3','唐山市','0315'); 
    
    CREATE TABLE District(
    	Id int ,
    	CityId int ,
    	Name varchar(50),
    	PostCode varchar(50)
    )row_format=dynamic engine=innodb default charset utf8;
    
    insert into District values('1','1','东城区','100010'); 
    insert into District values('2','1','西城区','100032'); 
    insert into District values('3','1','崇文区','100061'); 
    insert into District values('4','1','宣武区','100054'); 
    insert into District values('5','1','朝阳区','100020'); 
    insert into District values('6','1','丰台区','100071'); 
    insert into District values('7','1','石景山区','100043'); 

      一看,乖乖,这不就是一对多的关系吗?于是想到用MyBatis处理即可。参考myBatis系列之四:关联数据的查询【Mybatis高级映射】一对一映射、一对多映射、多对多映射很快就写出来了。

    Configuration.xml

    <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">  
      
    <configuration>  
        <typeAliases><!-- 别名 -->  
            <typeAlias alias="Province" type="com.bijian.study.dto.Province" />
            <typeAlias alias="City" type="com.bijian.study.dto.City" />
            <typeAlias alias="District" type="com.bijian.study.dto.District" />
        </typeAliases>  
          
        <environments default="development">  
          <environment id="development">  
            <transactionManager type="JDBC"/>  
            <dataSource type="POOLED"><!-- 数据源 -->  
                <property name="driver" value="com.mysql.jdbc.Driver" />  
                <property name="url" value="jdbc:mysql://10.107.96.172:3306/test" />  
                <property name="username" value="test" />  
                <property name="password" value="test" />  
            </dataSource>  
          </environment>  
        </environments>
          
        <mappers><!-- ORM映射文件 -->  
            <mapper resource="com/bijian/study/dto/Province.xml" />
            <mapper resource="com/bijian/study/dto/City.xml" />
            <mapper resource="com/bijian/study/dto/District.xml" />
        </mappers>  
    </configuration>

    log4j2.xml

    <?xml version="1.0" encoding="UTF-8"?>  
    <configuration status="OFF">  
      <appenders>  
        <Console name="Console" target="SYSTEM_OUT">  
          <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>  
        </Console>  
      </appenders>  
      <loggers>  
        <root level="info">  
          <appender-ref ref="Console"/>  
        </root>  
      </loggers>  
    </configuration>

    ProvinceMapper.java

    package com.bijian.study.dao;
    
    import java.util.List;
    
    import com.bijian.study.dto.Province;
    
    public interface ProvinceMapper {
        
        Province getProvinceById(int id);
        List<Province> getProvinceList();
        
        List<Province> getAllProvinceList();
    }

    Province.java

    package com.bijian.study.dto;
    
    import java.util.List;
    
    public class Province {
    
        private int id;
        private String name;
        private int orderid;
        private List<City> subs;
        
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getOrderid() {
            return orderid;
        }
        public void setOrderid(int orderid) {
            this.orderid = orderid;
        }
        public List<City> getSubs() {
          return subs;
        }
        public void setSubs(List<City> subs) {
          this.subs = subs;
        }
    }

    Province.xml

    <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.bijian.study.dao.ProvinceMapper">
    	
    	<resultMap type="Province" id="provinceList1">
    		<id column="Id" property="id" />
    		<result column="Name" property="name" />
    		<result column="orderid" property="orderid" />
    	</resultMap>
    
    	<select id="getProvinceById" parameterType="int" resultType="Province">
    		select * from Province where Id = #{id}
    	</select>
    
    	<select id="getProvinceList" resultMap="provinceList1">
    		select * from Province
    	</select>
    	
    	<resultMap type="Province" id="provinceList">
    		<result column="p_id" property="id" />
    		<result column="p_name" property="name" />
    		<!-- Province属性映射到City类 -->
    		<collection property="subs" ofType="City">
    			<id column="c_id" property="id" />
    			<result column="c_provinceId" property="provinceId"/>
    			<result column="c_name" property="name" />
    			<result column="c_areaCode" property="areaCode" />
    			<!-- District属性映射到District类 -->
    			<collection property="subs" ofType="District">
    				<id column="d_id" property="id" />
    				<result column="d_cityId" property="cityId" />
    				<result column="d_name" property="name" />
    				<result column="d_postCode" property="postCode" />	
    			</collection>
    		</collection>
    	</resultMap>
    
    	<select id="getAllProvinceList" resultMap="provinceList">
    		select p.Id p_id, p.Name p_name, c.Id c_id, c.ProvinceId c_provinceId, c.Name c_name, c.AreaCode c_areaCode, d.Id d_id, d.CityId d_cityId, d.Name d_name, d.PostCode d_postCode
    		from Province p inner join City c on p.Id=c.ProvinceId
    		inner join District d on c.Id=d.CityId
    	</select>
    </mapper>

    Main.java

    package com.bijian.study;
    
    import java.io.IOException;
    import java.io.Reader;
    import java.util.List;
    
    import org.apache.ibatis.io.Resources;
    import org.apache.ibatis.session.SqlSession;
    import org.apache.ibatis.session.SqlSessionFactory;
    import org.apache.ibatis.session.SqlSessionFactoryBuilder;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import com.bijian.study.dao.ProvinceMapper;
    import com.bijian.study.dto.Province;
    import com.fasterxml.jackson.databind.ObjectMapper;
    
    public class Main {
        
        private static final Logger log = LoggerFactory.getLogger(Main.class);  
        private static SqlSessionFactory sqlSessionFactory;  
      
        private static Reader reader;
        
        public static void main(String[] args) {
            try {
                reader = Resources.getResourceAsReader("Configuration.xml");  
                sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
                
                SqlSession session = sqlSessionFactory.openSession();
                
                ProvinceMapper mapper = session.getMapper(ProvinceMapper.class);  
                List<Province> provinceList = mapper.getAllProvinceList();
                log.info("{}", provinceList.size());
                
                ObjectMapper objMapper = new ObjectMapper();
                String provinceListStr = objMapper.writeValueAsString(provinceList);
                
                log.info("{}", provinceListStr);
            } catch (IOException e) {  
                log.error("Error thrown while reading the configuration: {}", e);  
            } finally {  
                if (reader != null) {  
                    try {  
                        reader.close();  
                    } catch (IOException e) {  
                        log.error("Error thrown while closing the reader: {}", e);  
                    }  
                }  
            }  
        }
    }

    运行Main.java,结果如下:


      当然,由于在实际应用中,根本无需id、cityId等,postCode、areaCode也统一用code,所以修改一下对应的sqlMapper及dto,详见附件工程包《JsonTransfer.rar》,运行Main2.java结果如下所示:

    展开全文
  • 全国地区 细分至省市区县街道 element级联选择器适用 全国地区 细分至省市区县街道 element级联选择器适用 全国地区 细分至省市区县街道 element级联选择器适用
  • 印尼地区到市区的完整区域列表,格式为JSON。 对于希望用户选择家乡的开发人员很有用。 某些地区的街道城市不完整。 非常感谢任何人想要帮助完成它。 要将JSON文件读入PHP数组中,请使用: $json = file_get_...
  • NULL 博文链接:https://bijian1013.iteye.com/blog/2391682
  • 最近在做app登录的时候,因为...根据短信提供商支持的国家,简单写了java代码生成了json [ { "countrys": [ { "name": "中国大陆", "number": "+86" ...

    最近在做app登录的时候,因为需要支持国外手机号注册和登录,所以就涉及到国际电话区号的选择。根据短信提供商支持的国家,简单写了java代码生成了json

    [
        {
            "countrys": [
                {
                    "name": "中国大陆",
                    "number": "+86"
                },
                {
                    "name": "香港 (中华人民共和国)",
                    "number": "+852"
                },
                {
                    "name": "澳门 (中华人民共和国)",
                    "number": "+853"
                }
            ],
            "name": "常用地区"
        },
        {
            "countrys": [
                {
                    "name": "埃及",
                    "number": "+20"
                },
                {
                    "name": "奥地利",
                    "number": "+43"
                },
                {
                    "name": "阿根廷",
                    "number": "+54"
                },
                {
                    "name": "澳洲",
                    "number": "+61"
                },
                {
                    "name": "阿富汗",
                    "number": "+93"
                },
                {
                    "name": "阿尔及利亚",
                    "number": "+213"
                },
                {
                    "name": "安哥拉",
                    "number": "+244"
                },
                {
                    "name": "阿森松岛",
                    "number": "+247"
                },
                {
                    "name": "埃塞俄比亚",
                    "number": "+251"
                },
                {
                    "name": "阿鲁巴 (荷兰王国)",
                    "number": "+297"
                },
                {
                    "name": "爱尔兰共和国",
                    "number": "+353"
                },
                {
                    "name": "阿尔巴尼亚",
                    "number": "+355"
                },
                {
                    "name": "爱沙尼亚",
                    "number": "+372"
                },
                {
                    "name": "安道尔",
                    "number": "+376"
                },
                {
                    "name": "澳门 (中华人民共和国)",
                    "number": "+853"
                },
                {
                    "name": "阿曼",
                    "number": "+968"
                },
                {
                    "name": "阿拉伯联合酋长国",
                    "number": "+971"
                },
                {
                    "name": "阿塞拜疆",
                    "number": "+994"
                },
                {
                    "name": "安圭拉",
                    "number": "+1264"
                },
                {
                    "name": "安提瓜和巴布达",
                    "number": "+1268"
                }
            ],
            "name": "a"
        },
        {
            "countrys": [
                {
                    "name": "比利时",
                    "number": "+32"
                },
                {
                    "name": "波兰",
                    "number": "+48"
                },
                {
                    "name": "巴西",
                    "number": "+55"
                },
                {
                    "name": "巴基斯坦",
                    "number": "+92"
                },
                {
                    "name": "布基纳法索",
                    "number": "+226"
                },
                {
                    "name": "贝宁",
                    "number": "+229"
                },
                {
                    "name": "布隆迪",
                    "number": "+257"
                },
                {
                    "name": "博茨瓦纳",
                    "number": "+267"
                },
                {
                    "name": "冰岛",
                    "number": "+354"
                },
                {
                    "name": "保加利亚",
                    "number": "+359"
                },
                {
                    "name": "白俄罗斯",
                    "number": "+375"
                },
                {
                    "name": "波斯尼亚与赫塞哥维纳",
                    "number": "+387"
                },
                {
                    "name": "伯利兹",
                    "number": "+501"
                },
                {
                    "name": "巴拿马",
                    "number": "+507"
                },
                {
                    "name": "玻利维亚",
                    "number": "+591"
                },
                {
                    "name": "巴拉圭",
                    "number": "+595"
                },
                {
                    "name": "博内尔岛,圣尤斯特歇斯和",
                    "number": "+599"
                },
                {
                    "name": "巴布亚新几内亚",
                    "number": "+675"
                },
                {
                    "name": "巴勒斯坦",
                    "number": "+930"
                },
                {
                    "name": "巴林",
                    "number": "+973"
                },
                {
                    "name": "不丹",
                    "number": "+975"
                },
                {
                    "name": "巴哈马",
                    "number": "+1242"
                },
                {
                    "name": "巴巴多斯",
                    "number": "+1246"
                },
                {
                    "name": "百慕大 (英国)",
                    "number": "+1441"
                },
                {
                    "name": "波多黎各 (美国)",
                    "number": "+1787"
                }
            ],
            "name": "b"
        },
        {
            "countrys": [
                {
                    "name": "查德",
                    "number": "+235"
                },
                {
                    "name": "赤道几内亚",
                    "number": "+240"
                }
            ],
            "name": "c"
        },
        {
            "countrys": [
                {
                    "name": "丹麦",
                    "number": "+45"
                },
                {
                    "name": "德国",
                    "number": "+49"
                },
                {
                    "name": "多哥",
                    "number": "+228"
                },
                {
                    "name": "东帝汶",
                    "number": "+670"
                },
                {
                    "name": "东加",
                    "number": "+676"
                },
                {
                    "name": "多米尼克",
                    "number": "+1767"
                },
                {
                    "name": "多米尼加共和国",
                    "number": "+1809"
                }
            ],
            "name": "d"
        },
        {
            "countrys": [
                {
                    "name": "俄罗斯",
                    "number": "+7"
                },
                {
                    "name": "厄瓜多尔",
                    "number": "+593"
                }
            ],
            "name": "e"
        },
        {
            "countrys": [
                {
                    "name": "法国",
                    "number": "+33"
                },
                {
                    "name": "菲律宾",
                    "number": "+63"
                },
                {
                    "name": "佛得角",
                    "number": "+238"
                },
                {
                    "name": "法罗群岛 (丹麦)",
                    "number": "+298"
                },
                {
                    "name": "芬兰",
                    "number": "+358"
                },
                {
                    "name": "法属圭亚那 (法国)",
                    "number": "+594"
                },
                {
                    "name": "法属波利尼西亚 (法国)",
                    "number": "+689"
                },
                {
                    "name": "斐济",
                    "number": "+679"
                }
            ],
            "name": "f"
        },
        {
            "countrys": [
                {
                    "name": "古巴",
                    "number": "+53"
                },
                {
                    "name": "哥伦比亚",
                    "number": "+57"
                },
                {
                    "name": "冈比亚",
                    "number": "+220"
                },
                {
                    "name": "刚果共和国",
                    "number": "+242"
                },
                {
                    "name": "刚果民主共和国",
                    "number": "+243"
                },
                {
                    "name": "格陵兰 (丹麦)",
                    "number": "+299"
                },
                {
                    "name": "哥斯达黎加",
                    "number": "+506"
                },
                {
                    "name": "瓜德罗普岛",
                    "number": "+590"
                },
                {
                    "name": "圭亚那",
                    "number": "+592"
                },
                {
                    "name": "格林纳达",
                    "number": "+1473"
                },
                {
                    "name": "关岛 (美国)",
                    "number": "+1671"
                }
            ],
            "name": "g"
        },
        {
            "countrys": [
                {
                    "name": "哈萨克",
                    "number": "+7"
                },
                {
                    "name": "荷兰",
                    "number": "+31"
                },
                {
                    "name": "韩国",
                    "number": "+82"
                },
                {
                    "name": "黑山共和国",
                    "number": "+382"
                },
                {
                    "name": "洪都拉斯",
                    "number": "+504"
                },
                {
                    "name": "海地",
                    "number": "+509"
                }
            ],
            "name": "h"
        },
        {
            "countrys": [
                {
                    "name": "加拿大",
                    "number": "+1"
                },
                {
                    "name": "几内亚",
                    "number": "+224"
                },
                {
                    "name": "加纳",
                    "number": "+233"
                },
                {
                    "name": "加蓬",
                    "number": "+241"
                },
                {
                    "name": "几内亚比绍",
                    "number": "+245"
                },
                {
                    "name": "吉布提",
                    "number": "+253"
                },
                {
                    "name": "津巴布韦",
                    "number": "+263"
                },
                {
                    "name": "捷克",
                    "number": "+420"
                },
                {
                    "name": "基里巴斯",
                    "number": "+686"
                },
                {
                    "name": "柬埔寨",
                    "number": "+855"
                },
                {
                    "name": "吉尔吉斯",
                    "number": "+996"
                }
            ],
            "name": "j"
        },
        {
            "countrys": [
                {
                    "name": "科特迪瓦",
                    "number": "+225"
                },
                {
                    "name": "喀麦隆",
                    "number": "+237"
                },
                {
                    "name": "肯尼亚",
                    "number": "+254"
                },
                {
                    "name": "科摩罗",
                    "number": "+269"
                },
                {
                    "name": "克罗地亚",
                    "number": "+385"
                },
                {
                    "name": "库拉索 (荷兰王国)",
                    "number": "+599"
                },
                {
                    "name": "库克群岛 (新西兰)",
                    "number": "+682"
                },
                {
                    "name": "科威特",
                    "number": "+965"
                },
                {
                    "name": "卡达",
                    "number": "+974"
                },
                {
                    "name": "开曼群岛 (英国)",
                    "number": "+1345"
                }
            ],
            "name": "k"
        },
        {
            "countrys": [
                {
                    "name": "罗马尼亚",
                    "number": "+40"
                },
                {
                    "name": "利比亚",
                    "number": "+218"
                },
                {
                    "name": "利比里亚",
                    "number": "+231"
                },
                {
                    "name": "卢旺达",
                    "number": "+250"
                },
                {
                    "name": "留尼汪 (法国)",
                    "number": "+262"
                },
                {
                    "name": "莱索托",
                    "number": "+266"
                },
                {
                    "name": "卢森堡",
                    "number": "+352"
                },
                {
                    "name": "立陶宛",
                    "number": "+370"
                },
                {
                    "name": "拉脱维亚",
                    "number": "+371"
                },
                {
                    "name": "列支敦士登",
                    "number": "+423"
                },
                {
                    "name": "老挝",
                    "number": "+856"
                },
                {
                    "name": "黎巴嫩",
                    "number": "+961"
                }
            ],
            "name": "l"
        },
        {
            "countrys": [
                {
                    "name": "美国",
                    "number": "+1"
                },
                {
                    "name": "秘鲁",
                    "number": "+51"
                },
                {
                    "name": "墨西哥",
                    "number": "+52"
                },
                {
                    "name": "马来西亚",
                    "number": "+60"
                },
                {
                    "name": "缅甸",
                    "number": "+95"
                },
                {
                    "name": "摩洛哥",
                    "number": "+212"
                },
                {
                    "name": "毛里塔尼亚",
                    "number": "+222"
                },
                {
                    "name": "马里共和国",
                    "number": "+223"
                },
                {
                    "name": "毛里求斯",
                    "number": "+230"
                },
                {
                    "name": "莫桑比克",
                    "number": "+258"
                },
                {
                    "name": "马达加斯加",
                    "number": "+261"
                },
                {
                    "name": "马拉维",
                    "number": "+265"
                },
                {
                    "name": "马约特",
                    "number": "+269"
                },
                {
                    "name": "马其顿",
                    "number": "+389"
                },
                {
                    "name": "马耳他",
                    "number": "+356"
                },
                {
                    "name": "摩尔多瓦",
                    "number": "+373"
                },
                {
                    "name": "摩纳哥",
                    "number": "+377"
                },
                {
                    "name": "马提尼克 (法国)",
                    "number": "+596"
                },
                {
                    "name": "孟加拉国",
                    "number": "+880"
                },
                {
                    "name": "马尔代夫",
                    "number": "+960"
                },
                {
                    "name": "蒙古国",
                    "number": "+976"
                },
                {
                    "name": "美属维尔京群岛 (美国)",
                    "number": "+1340"
                },
                {
                    "name": "蒙塞拉特岛 (英国)",
                    "number": "+1664"
                },
                {
                    "name": "美属萨摩亚 (美国)",
                    "number": "+1684"
                }
            ],
            "name": "m"
        },
        {
            "countrys": [
                {
                    "name": "南非",
                    "number": "+27"
                },
                {
                    "name": "挪威",
                    "number": "+47"
                },
                {
                    "name": "南苏丹",
                    "number": "+211"
                },
                {
                    "name": "尼日",
                    "number": "+227"
                },
                {
                    "name": "尼日利亚",
                    "number": "+234"
                },
                {
                    "name": "纳米比亚",
                    "number": "+264"
                },
                {
                    "name": "尼加拉瓜",
                    "number": "+505"
                },
                {
                    "name": "尼泊尔",
                    "number": "+977"
                }
            ],
            "name": "n"
        },
        {
            "countrys": [
                {
                    "name": "葡萄牙",
                    "number": "+351"
                },
                {
                    "name": "帕劳",
                    "number": "+680"
                }
            ],
            "name": "p"
        },
        {
            "countrys": [
                {
                    "name": "乔治亚",
                    "number": "+995"
                }
            ],
            "name": "q"
        },
        {
            "countrys": [
                {
                    "name": "瑞士",
                    "number": "+41"
                },
                {
                    "name": "瑞典",
                    "number": "+46"
                },
                {
                    "name": "日本",
                    "number": "+81"
                }
            ],
            "name": "r"
        },
        {
            "countrys": [
                {
                    "name": "斯里兰卡",
                    "number": "+94"
                },
                {
                    "name": "塞内加尔",
                    "number": "+221"
                },
                {
                    "name": "狮子山共和国",
                    "number": "+232"
                },
                {
                    "name": "圣多美普林西比",
                    "number": "+239"
                },
                {
                    "name": "塞舌尔",
                    "number": "+248"
                },
                {
                    "name": "苏丹",
                    "number": "+249"
                },
                {
                    "name": "索马里",
                    "number": "+252"
                },
                {
                    "name": "斯威士兰",
                    "number": "+268"
                },
                {
                    "name": "塞浦路斯",
                    "number": "+357"
                },
                {
                    "name": "圣马力诺",
                    "number": "+378"
                },
                {
                    "name": "塞尔维亚共和国",
                    "number": "+381"
                },
                {
                    "name": "斯洛文尼亚",
                    "number": "+386"
                },
                {
                    "name": "斯洛伐克",
                    "number": "+421"
                },
                {
                    "name": "萨尔瓦多",
                    "number": "+503"
                },
                {
                    "name": "圣皮耶与密克隆群岛 (法国)",
                    "number": "+508"
                },
                {
                    "name": "圣马丁岛(荷兰部分)",
                    "number": "+590"
                },
                {
                    "name": "苏里南",
                    "number": "+597"
                },
                {
                    "name": "所罗门群岛",
                    "number": "+677"
                },
                {
                    "name": "萨摩亚",
                    "number": "+685"
                },
                {
                    "name": "沙特阿拉伯",
                    "number": "+966"
                },
                {
                    "name": "圣卢西亚",
                    "number": "+1758"
                },
                {
                    "name": "圣文森及格林纳丁",
                    "number": "+1784"
                },
                {
                    "name": "圣克里斯多福与尼维斯",
                    "number": "+1869"
                }
            ],
            "name": "s"
        },
        {
            "countrys": [
                {
                    "name": "泰国",
                    "number": "+66"
                },
                {
                    "name": "土耳其",
                    "number": "+90"
                },
                {
                    "name": "突尼斯",
                    "number": "+216"
                },
                {
                    "name": "坦桑尼亚",
                    "number": "+255"
                },
                {
                    "name": "台湾",
                    "number": "+886"
                },
                {
                    "name": "塔吉克",
                    "number": "+992"
                },
                {
                    "name": "土库曼",
                    "number": "+993"
                },
                {
                    "name": "土克凯可群岛 (英国)",
                    "number": "+1649"
                },
                {
                    "name": "特立尼达和多巴哥",
                    "number": "+1868"
                }
            ],
            "name": "t"
        },
        {
            "countrys": [
                {
                    "name": "委内瑞拉",
                    "number": "+58"
                },
                {
                    "name": "乌干达",
                    "number": "+256"
                },
                {
                    "name": "乌克兰",
                    "number": "+380"
                },
                {
                    "name": "危地马拉",
                    "number": "+502"
                },
                {
                    "name": "乌拉圭",
                    "number": "+598"
                },
                {
                    "name": "文莱",
                    "number": "+673"
                },
                {
                    "name": "瓦努阿图",
                    "number": "+678"
                },
                {
                    "name": "乌兹别克",
                    "number": "+998"
                }
            ],
            "name": "w"
        },
        {
            "countrys": [
                {
                    "name": "希腊",
                    "number": "+30"
                },
                {
                    "name": "西班牙",
                    "number": "+34"
                },
                {
                    "name": "匈牙利",
                    "number": "+36"
                },
                {
                    "name": "新西兰",
                    "number": "+64"
                },
                {
                    "name": "新加坡",
                    "number": "+65"
                },
                {
                    "name": "新喀里多尼亚 (法国)",
                    "number": "+687"
                },
                {
                    "name": "香港 (中华人民共和国)",
                    "number": "+852"
                },
                {
                    "name": "叙利亚",
                    "number": "+963"
                }
            ],
            "name": "x"
        },
        {
            "countrys": [
                {
                    "name": "意大利",
                    "number": "+39"
                },
                {
                    "name": "英国",
                    "number": "+44"
                },
                {
                    "name": "印度尼西亚",
                    "number": "+62"
                },
                {
                    "name": "越南",
                    "number": "+84"
                },
                {
                    "name": "印度",
                    "number": "+91"
                },
                {
                    "name": "伊朗",
                    "number": "+98"
                },
                {
                    "name": "亚美尼亚",
                    "number": "+374"
                },
                {
                    "name": "约旦",
                    "number": "+962"
                },
                {
                    "name": "伊拉克",
                    "number": "+964"
                },
                {
                    "name": "也门",
                    "number": "+967"
                },
                {
                    "name": "以色列",
                    "number": "+972"
                },
                {
                    "name": "英属维尔京群岛 (英国)",
                    "number": "+1284"
                },
                {
                    "name": "牙买加",
                    "number": "+1876"
                }
            ],
            "name": "y"
        },
        {
            "countrys": [
                {
                    "name": "智利",
                    "number": "+56"
                },
                {
                    "name": "中非共和国",
                    "number": "+236"
                },
                {
                    "name": "赞比亚",
                    "number": "+260"
                },
                {
                    "name": "直布罗陀 (英国)",
                    "number": "+350"
                }
            ],
            "name": "z"
        }
    ]

     

    展开全文
  • jQuery json省市区街道四级联动地址选择插件,适合做收货地址的地区四级联动代码。
  • countryAreaCode.json

    2020-03-08 20:49:41
    一个关于选择国家地区的一个区号编码json文件,要50个字真凑不齐可咋整呢 一个关于选择国家地区的一个区号编码json文件,要50个字真凑不齐可咋整呢 一个关于选择国家地区的一个区号编码json文件,要50个字真凑不齐可...
  • 全国地区信息的json数据和xml数据。json数据提供二个级别城市,xml数据提供了三个级别城市。适合网站表单提交的城市选择
  • 适用于前端开发时 使用的 省市区三级联动 选择 和 位置定位反显 省市区area.js数据, 囊括全国地区及各级地区的完整数据
  • 三级联动高德全国地区json数据,分级明确,包括省、市、区/县(包括所在第经纬度、区号、行政区编码),前端必备的地区选择控件数据
  • android全国地区选择

    热门讨论 2016-08-04 13:47:53
    本地json文件集合,实现android全国地区三级省市区选择
  • 上图是省市级联菜单的效果图,省市地区的数据文件开发者可以下载直接使用 实现级联菜单 难点1:三个下拉框之间的关联问题,这里涉及到监听事件! 难点2:根据数据的结构,如何将地区数据对应到正确的下拉框位置上。...

    省市级联菜单效果图

    上图是省市级联菜单的效果图,省市地区的数据文件开发者可以下载直接使用

    实现级联菜单
    难点1:三个下拉框之间的关联问题,这里涉及到监听事件!
    难点2:根据数据的结构,如何将地区数据对应到正确的下拉框位置上。

    需要注意事项

    1. 当用户选择了省/直辖市的内容后,市/区的下拉框内容会被更新,县/市的下拉框是暂时不变的。
    2. 当用户选择市/区的内容后,县/市的下拉框内容更新。
    3. 当用户 修改省/直辖市的内容后,市/区和县/市的下拉框内容会被清空,并且显示默认的请选择**。
    4. 当用户只修改市/区内容时,县/市 下拉框内容被清空,并修改成市/区对应的县/市。
    1. 首先要预先准备好一个vue框架的空项目。如果不知道vue脚手架的搭建,可以看我下一篇文章。
    2. 其次,将我分享的省市地区的数据文件下载下来,放到项目的 src/assets目录下。
    3. 接下来正式开始,第一步,在 src/compontents目录下, 创建下拉框组件Dropdown.vue文件,写好下拉框模板。
    // 这段内容放在 <template></template> 中
     <span>
     // 这里 v-model 用来绑定数据,可以接收到用户改变后的省直辖市,方便我们寻找该省直辖市对应的市区
         <select v-model="province" @change="changeCity">
         // locaty是地区数据,因为当前是子组件,locaty是接受父组件传地区数据!
             <option v-for="(val, index) in locaty.options" :key="index" :value="val.province">{{val.province}}</option>
         </select>
         <select v-model="c" @change="changeCounty">
             <option v-for="(name, index) in city" :key="index" :value="name.name">{{name.name}}</option>
         </select>
         <select  v-model="cy">
             <option v-for="(area, index) in county" :key="index" :value="area">{{area}}</option>
         </select>
     </span>
    
    1. Dropdown.vue的script代码,详细见代码注释:
    <script>
    export default {
        name: 'Dropdown',
        props : ["locaty"], // 父组件中接受的地区数据
        data() {
            return {
                province : '选择省/直辖市' ,
                // 选择市区
                c : '选择市/区',
                city : [{ name : '选择市/区' }],
                // 县市
                cy : '选择县/市',
                county : ['选择县/市']
            }
        },
        methods:{
            // 当省/直辖市选择出现变化的时候,要修改city和county
            changeCity(){
            	// 恢复默认状态
                this.c = '选择市/区'; 
                this.cy = '选择县/市'; 
                // 删除当前的city和county数组第一个数据之后的所有数据,否则会将上一次选择的内容和本次选择的内容拼接到一起!
                this.city.splice(1) 
                this.county.splice(1);
                // 查找地区数据中是否包含用户当前选择的省直辖市对应的市区数据,并将数据保存到city数组中。
                for(var item in this.locaty.options){
                    if(this.locaty.options[item].province == this.province){
                        this.city = this.city.concat(this.locaty.options[item].city);
                    }
                }
            },
            // 修改县/市
            changeCounty(){
            	// 同上:恢复默认状态
                this.cy = '选择县/市';
                this.county.splice(1);
                // 查找用户当前选择的
                this.locaty.options.forEach(ele => {
                // 先确定当前的省份
                    if(ele.province == this.province){
                        ele.city.forEach((ele)=>{
                        // 这里确定市区
                            if(ele.name == this.c){
                            // 将市区对应的县市地区数据拼接到county中;
                                this.county = this.county.concat(ele.area);
                            }
                        })
                    }
                });
            }
        }
        
    }
    </script>
    
    1. 到此,子组件的工作就已经完成,该父组件调用子组件Dropdown了,父组件src/pages/Uregister.vue文件。
    <template>
    	<div>
    		// 4. 使用下拉框组件 , 用locaty接收地区数据city
    		<Dropdown :locaty="city" ></Dropdown>
    	</div>
    </template>
    <script>
    // 1. 首先在父组件中引入地区数据
    import { city } from '../assets/data.js'
    // 2. 引入下拉框组件
    import Dropdown from '../components/Dropdown'
    export default {
        name: 'Uregister',
        components : { // 3. 注册下拉框组件
            Dropdown
        },
    }
    </script>
    
    1. 以上几步就完成了省市区三级级联菜单的功能,具体css样式就随意了,有更好的办法欢迎留言讨论。
      级联菜单示意图
    展开全文
  • 地区选择组件

    千次阅读 2014-04-03 11:05:28
    很多应用都会用到地区选择,有些是直接选择城市(例如大众点评、58同城等),有些是先选择省再选择城市(例如微信),这里要做的是类似微信的做法,先选择省份再选择城市。 效果图: 地区数据格式(文件为city....

    转帖请注明本文出自pkxutao的博客(http://blog.csdn.net/pkxutao/article/details/22854257),请尊重他人的辛勤劳动成果,谢谢!

    很多应用都会用到地区选择,有些是直接选择城市(例如大众点评、58同城等),有些是先选择省再选择城市(例如微信),这里要做的是类似微信的做法,先选择省份再选择城市。

    效果图:



    地区数据格式(文件为city.json,保存在assets文件夹下):



    先解析出数据,保存为list:

    public List<String> getProvinceList() {
    		List<String> provinceList = new ArrayList<String>();// 省份
    		
    		String json = getData().toString();
    		try {
    			JSONArray data = new JSONArray(json);
    			for (int i = 0; i < data.length(); i++) {
    				JSONObject provinceObj = data.getJSONObject(i);
    				String province = provinceObj.getString("name");//获取省份
    				provinceList.add(province);//存入省份list里面
    				JSONArray citys = provinceObj.getJSONArray("citys");
    				List<String> cityList = new ArrayList<String>();// 相应的城市列表
    				for (int j = 0; j < citys.length(); j++) {
    					JSONObject cityObj = citys.getJSONObject(j);
    					Iterator<String> keys = cityObj.keys();
    					 while(keys.hasNext()){//遍历城市列表
    						 String key = keys.next();
    						 String city = cityObj.getString(key);
    						 cityList.add(city);//存入城市list
    						 codeMap.put(city, key);//存入一个城市为key,code为value的hashmap,这样可以通过城市获取code或者通过code获取城市
    					 }
    					 if (j == citys.length()-1) {
    						 cityMap.put(province, cityList);//如果这个省的城市列表解析完成,就放入到一个省份为key,城市列表为value的hashmap中
    					}
    				}
    			}
    		} catch (JSONException e) {
    			e.printStackTrace();
    		}
    		return provinceList;
    	}
    展示时,先通过getProvinceList获取省份列表,通过listview展示,当用户点击某个省份的时候,判断是否是直辖市,如果是直辖市或者只有一个城市,则直接返回,如果有一个以上城市,则通过下面代码获取城市列表展示:

    public List<String> getCityList(String province) {
    		
    		return cityMap.get(province);
    	}
    ,用户选择后,返回数据需要加上code,获取code函数:

    public String getCode(String city){
    		return codeMap.get(city);
    	}
    这样,在开始选择地区的那个activity通过onActivityResult接收选择的地区数据就可以了。

    这里用code的原因是因为需要统一地区,例如,如果有几个终端来输入西藏,有些可能输入西藏自治区等,这样数据就不统一了,所以用code来统一数据很方便。

    前端从后端接收地区时也是通过code来辨别,那么怎样把code解析成地址呢?

    先通过code 获取city:

    public String getCity(String code){
    		getProvinceList() ;
    		String city = (String)keyString(codeMap, code);
    		return city;
    	}
    再通过city获取province(省份):

    public String getProvince(String city){
    			Iterator<String> it= cityMap.keySet().iterator();
    	          while(it.hasNext()){
    	        	  String province = it.next();
    	        	  List<String> cityList = cityMap.get(province);
    	        	  for (int i = 0; i < cityList.size(); i++) {
    	        		  if (cityList.get(i).equals(city)) {
    						return province;
    					}
    				}
    	          }
    	          return null;
    	}

    至此组件完成,主界面如图:




    DEMO下载



    展开全文
  • {"city": {"福建省": ["福州市","厦门市","莆田市","三明市","泉州市","漳州市","南平市","龙岩市","宁德市"],"西藏自治区": ["拉萨市","昌都地区","山南地区","日喀则地区","那曲地区","阿里地区","林芝地区"],...
  • 全国各省份,各城市,各区县的json数据,方便快速开发地区选择的应用。利用本json很容易开发出来三级联动的地区菜单
  • 编辑区域地图json数据

    2019-11-08 16:05:32
    一直在该地址:地图选择器 获取地图json,今天发现没有庐山市的GeoJSON数据,于是自己编辑了庐山市的json文件。 1.获取地区边界坐标数据:https://www.17ditu.com/tool/boundary.html 2.复制一个区域地图json文件,...
  • jqueryjson.zip

    2020-05-13 18:15:33
    利用jquery,省市区三级联动,五种不同的demo,样式齐全.无任何依赖的轻量级地区选择组件.
  • 多语言列表 ... 选择菜单 UL菜单 JSON格式 您将拥有哪些类型的数据列表? 国家名称 国家原名 大写名称 国家ISO_2编码 国家ISO_3编码 国家/地区电话代码 特征 国家名称按字母顺序排列 大写字母名称按字
  • 仿IOS的地区选择效果

    千次阅读 2016-11-07 18:00:46
    根据开源项目:https://github.com/saiwu-bigkoo/Android-PickerView/,练习了一下地区选择器。首先非常感谢这位童鞋的无私分享!之所以重新动手练习下,是因为该开源项目里面没有完整的json数据串,我从网上找了一...
  • 一、背景 最近刚刚做完一个中文汉字笔画...【我的Android进阶之旅】Android实现中文汉字笔划(笔画)排序、中文拼音排序、英文排序的国家地区选择界面 【我的Java开发学习之旅】如何实现中文汉字进行笔划(笔画)排序? ...
  • 地区选择控件杂记

    2017-09-11 11:08:00
    1.json数据读取 private void initJsonData() { try { StringBuffer sb = new StringBuffer(); InputStream is = getAssets().open("city.json");//打开json数据 by...
  • 全国省市县JSON数据

    2018-11-22 14:48:39
    全国省市县都有,可用来做地区定位,选择地区,切换地区用的
  • JS解析JSON字符串

    2016-11-04 14:46:00
    思路:因为数据比较杂乱,所以我选择传递的数据类型是Json格式,但是数据展示时需要解析成单个的字符串,赋值给Lable标签 一、JSON字符串解析 Json格式字符串(键/值) {"lblTime":"2016-11-04 14:15:26",...
  • 地区选择

    2016-02-19 13:02:00
    xml方式:有Dmeo,点此下载 一个县级为一个对象json格式数据(详细):点此下载 ...仿美团选择城市 db文件,带有模糊搜索和字母导航电此下载 转载于:https://www.cnblogs.com/zzw1994/p/5200670.html...
  • Android——实现全国省市区地区选择

    万次阅读 多人点赞 2016-08-04 14:03:06
    android的地区选择,这个实在是太...只不过网络请求速度慢了些,写了个demo,在本地的省市区json文件集合实现全国三级地区选择,这里我也主要贴下主要的代码,后面把项目的下载地址分享出来。项目结构: 主要代码,S
  • 我们在注册时,可以选择手机号注册,而手机号是有国家或地区码归属的国家代码,区号码,手机区号Json文件。
  • vue加载本地json文件

    2018-11-29 15:40:00
    背景:做地区跟行业级联下拉选择,因为想做成可以搜索的,所以必须一次加载数据,后台有做memcache缓存,但因为数据量大,还是比较费时间,所以做成本地文件,简单记录一下 准备数据,放到static下 修改...

空空如也

空空如也

1 2 3 4 5 ... 12
收藏数 236
精华内容 94
热门标签
关键字:

地区选择json