看格式,是string格式的,需要转成json
{
"result": {
"formatted_address": "广西壮族自治区南宁市青秀区南湖街道龙居苑东南约53米",
"location": {
"lon": 108.3856,
"lat": 22.8181
},
"addressComponent": {
"address": "龙居苑",
"town": "南湖街道",
"nation": "中国",
"city": "南宁市",
"county_code": "156450103",
"poi_position": "东南",
"county": "青秀区",
"city_code": "156450100",
"address_position": "东南",
"poi": "龙居苑",
"province_code": "156450000",
"town_code": "156450103004",
"province": "广西壮族自治区",
"road": "云景路",
"road_distance": 100,
"address_distance": 53,
"poi_distance": 53
}
},
"msg": "ok",
"status": "0"
}
上代码
JSONObject resultObject = HttpUtils.doGet(url, requestObject1);
System.out.println("========= geocoder resultObject ==========");
System.out.println(resultObject);
String result = resultObject.getString("result");
Map<String, Object> map1 = JSON.parseObject(result, new TypeReference<Map<String, Object>>(){});
MapLocation mapLocation = new MapLocation();
String locationStr = map1.get("location").toString();
Map<String, Object> location = JSON.parseObject(locationStr, new TypeReference<Map<String, Object>>(){});
String addressComponentStr = map1.get("addressComponent").toString();
Map<String, Object> addressComponent = JSON.parseObject(addressComponentStr, new TypeReference<Map<String, Object>>(){});
mapLocation.setCity(result);
mapLocation.setLat(location.get("lat").toString());
mapLocation.setLon(location.get("lon").toString());
mapLocation.setProvince(addressComponent.get("province").toString());
mapLocation.setProvinceCode(addressComponent.get("province_code").toString());
mapLocation.setCity(addressComponent.get("city").toString());
mapLocation.setCityCode(addressComponent.get("city_code").toString());
mapLocation.setCounty(addressComponent.get("county").toString());
mapLocation.setCountyCode(addressComponent.get("county_code").toString());
mapLocation.setTown(addressComponent.get("town").toString());
mapLocation.setTownCode(addressComponent.get("town_code").toString());
mapLocation.setRoad(addressComponent.get("road").toString());
mapLocation.setFormattedAddress(map1.get("formatted_address").toString());