java json string 类型转 json

看格式,是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());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值