行政区域查询-API文档-开发指南-Web服务 API | 高德地图API
private static void tm1(String s) throws IOException {String url="https://restapi.amap.com/v3/config/district?keywords=中华人民共和国&subdistrict=3&key=用户key";String sx = OkHttpUtils.get(url);System.out.println("s1 = " + sx);if (true) {return;}String path = "D:/jsonArr.json";String s1 = FileUtils.readFile(path);TTBen[] ttBens = GsonUtil.fromJsonToArr(s1, TTBen.class);for (TTBen ttBen : ttBens) {if (ttBen.getLevel().equals("country")) {} else if (ttBen.getLevel().equals("province")) {} else if (ttBen.getLevel().equals("district")) {}else if (ttBen.getLevel().equals("street")) {}
// if (ttBen.getCitycode().equals("district")) {
// ttBen.setCode(ttBen.getAdcode());
// ttBen.setParent_code(ttBen.getCitycode());
// }else if (ttBen.getCitycode().equals("city")) {
// ttBen.setCode(ttBen.getAdcode());
// ttBen.setParent_code(ttBen.getCitycode());
// }System.out.println("省: " + ttBen.getAdcode() + " " + ttBen.getName());// if (ttBen.getCitycode().equals("district")) {
// ttBen.setCode(ttBen.getAdcode());
// ttBen.setParent_code(ttBen.getCitycode());
// }else if (ttBen.getCitycode().equals("city")) {
// ttBen.setCode(ttBen.getAdcode());
// ttBen.setParent_code(ttBen.getCitycode());
// }}}
import java.util.List;public class TTBen {private String code;private String parent_code;private String citycode;private String adcode;private String name;private String center;private String level;private List<TTBen> districts;public String getCitycode() {return citycode;}public void setCitycode(String citycode) {this.citycode = citycode;}public String getAdcode() {return adcode;}public void setAdcode(String adcode) {this.adcode = adcode;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getCenter() {return center;}public void setCenter(String center) {this.center = center;}public String getLevel() {return level;}public void setLevel(String level) {this.level = level;}public List<TTBen> getDistricts() {return districts;}public void setDistricts(List<TTBen> districts) {this.districts = districts;}public String getCode() {return code;}public void setCode(String code) {this.code = code;}public String getParent_code() {return parent_code;}public void setParent_code(String parent_code) {this.parent_code = parent_code;}
}
返回的三级 包含了地级市的街道 "street" 了 数据还是需要自己整理