NutzCN Logo
问答 JSON转nutzmap时抛异常
发布于 2769天前 作者 蛋蛋的忧伤 2620 次浏览 复制 上一个帖子 下一个帖子
标签:

腾讯service根据经纬度获取详细地址:代码为:

public static void main(String[] args){
		String la ="37.467136";
		String lo = "121.442606";

		String url = "http://apis.map.qq.com/ws/geocoder/v1/?location=";
		url+=la+","+lo;
		url+="&key=OJSBZ-CJXR6-E3HSC-MY2QQ-AKX2O-52F2L&get_poi=1";


		Response response = Http.get(url);
		int code = response.getStatus();
		if(code == 200){
			String content = response.getContent();
			System.err.println(content);
            NutMap nm = Json.fromJson(NutMap.class, content);
            String rs = nm.get("result").toString();

            NutMap con = Json.fromJson(NutMap.class, rs);

            System.out.println(rs);


//            String addresss = (String) result.get("address");
//            System.out.println(addresss);
        }
	}

报错为:

Exception in thread "main" org.nutz.json.JsonException: !Json syntax error nearby [row:1,col:11 char '{'], reason: 'Unexpect Char'

json格式为:

{
    "status": 0,
    "message": "query ok",
    "request_id": "6273076850021408945",
    "result": {
        "location": {
            "lat": 37.467136,
            "lng": 121.442606
        },
        "address": "山东省烟台市莱山区迎春大街137号迎春大街",
        "formatted_addresses": {
            "recommend": "莱山区迎春大街科技创业大厦南100米",
            "rough": "莱山区迎春大街科技创业大厦南100米"
        },
        "address_component": {
            "nation": "中国",
            "province": "山东省",
            "city": "烟台市",
            "district": "莱山区",
            "street": "迎春大街",
            "street_number": "迎春大街137号"
        },
        "ad_info": {
            "adcode": "370613",
            "name": "中国,山东省,烟台市,莱山区",
            "location": {
                "lat": 37.467136,
                "lng": 121.442604
            },
            "nation": "中国",
            "province": "山东省",
            "city": "烟台市",
            "district": "莱山区"
        },
        "address_reference": {
            "business_area": {
                "title": "初家",
                "location": {
                    "lat": 37.467136,
                    "lng": 121.442604
                },
                "_distance": 0,
                "_dir_desc": "内"
            },
            "famous_area": {
                "title": "初家",
                "location": {
                    "lat": 37.467136,
                    "lng": 121.442604
                },
                "_distance": 0,
                "_dir_desc": "内"
            },
            "crossroad": {
                "title": "银海路/迎春大街(路口)",
                "location": {
                    "lat": 37.46912,
                    "lng": 121.444412
                },
                "_distance": 267,
                "_dir_desc": "西南"
            },
            "village": {
                "title": "初家",
                "location": {
                    "lat": 37.465309,
                    "lng": 121.440224
                },
                "_distance": 292.6,
                "_dir_desc": "东北"
            },
            "town": {
                "title": "黄海路街道",
                "location": {
                    "lat": 37.467136,
                    "lng": 121.442604
                },
                "_distance": 0,
                "_dir_desc": "内"
            },
            "street_number": {
                "title": "迎春大街137号",
                "location": {
                    "lat": 37.466961,
                    "lng": 121.442543
                },
                "_distance": 20.3,
                "_dir_desc": "附近"
            },
            "street": {
                "title": "迎春大街",
                "location": {
                    "lat": 37.467022,
                    "lng": 121.442749
                },
                "_distance": 12.8,
                "_dir_desc": "北"
            },
            "landmark_l1": {
                "title": "滨州医学院附属烟台光华医院",
                "location": {
                    "lat": 37.466999,
                    "lng": 121.444878
                },
                "_distance": 65.7,
                "_dir_desc": "西"
            },
            "landmark_l2": {
                "title": "科技创业大厦",
                "location": {
                    "lat": 37.468609,
                    "lng": 121.44223
                },
                "_distance": 98.4,
                "_dir_desc": "南"
            }
        },
        "poi_count": 10,
        "pois": [
            {
                "id": "2146190903708710928",
                "title": "科技创业大厦",
                "address": "山东省烟台市莱山区迎春大街133号",
                "category": "房产小区:商务楼宇",
                "location": {
                    "lat": 37.468609,
                    "lng": 121.44223
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 98.4,
                "_dir_desc": "南"
            },
            {
                "id": "411056606383669128",
                "title": "滨州医学院附属烟台光华医院",
                "address": "山东省烟台市莱山区光华路16号",
                "category": "医疗保健:综合医院",
                "location": {
                    "lat": 37.466999,
                    "lng": 121.444878
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 65.7,
                "_dir_desc": "西"
            },
            {
                "id": "7174587718934325113",
                "title": "烟台市莱山区地税局",
                "address": "山东省烟台市莱山区迎春大街135号",
                "category": "机构团体:工商税务机构",
                "location": {
                    "lat": 37.46764,
                    "lng": 121.442619
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 56.1,
                "_dir_desc": "附近"
            },
            {
                "id": "8400100000000003576024",
                "title": "中国农业银行莱山支行公交站",
                "address": "山东省烟台市莱山区中国农业银行莱山支行公交站",
                "category": "普通公交线路",
                "location": {
                    "lat": 37.467159,
                    "lng": 121.442696
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 8.5,
                "_dir_desc": ""
            },
            {
                "id": "8400100000000002701631",
                "title": "中国银行莱山支行公交站",
                "address": "山东省烟台市莱山区中国银行莱山支行公交站",
                "category": "普通公交线路",
                "location": {
                    "lat": 37.467159,
                    "lng": 121.442696
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 8.5,
                "_dir_desc": ""
            },
            {
                "id": "1717838572934777551",
                "title": "中国银行(莱山支行)",
                "address": "山东省烟台市莱山区迎春大街139号",
                "category": "银行金融:银行",
                "location": {
                    "lat": 37.46648,
                    "lng": 121.442162
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 82.8,
                "_dir_desc": "东北"
            },
            {
                "id": "15409042374162148868",
                "title": "金融国际大厦",
                "address": "山东省烟台市莱山区迎春大街中国银行南侧",
                "category": "房产小区:商务楼宇",
                "location": {
                    "lat": 37.466091,
                    "lng": 121.441628
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 144.9,
                "_dir_desc": "东北"
            },
            {
                "id": "4073035163773963248",
                "title": "科技创业大厦A座",
                "address": "山东省烟台市莱山区迎春大街133号",
                "category": "房产小区:商务楼宇",
                "location": {
                    "lat": 37.468861,
                    "lng": 121.442436
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 192.5,
                "_dir_desc": "南"
            },
            {
                "id": "3935996540801468891",
                "title": "科技创业大厦C座",
                "address": "山东省烟台市莱山区迎春大街海普路科技创业大厦",
                "category": "房产小区:商务楼宇",
                "location": {
                    "lat": 37.468262,
                    "lng": 121.442101
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 132.9,
                "_dir_desc": "南"
            },
            {
                "id": "13911306271788891163",
                "title": "科技创业大厦B座",
                "address": "山东省烟台市莱山区迎春大街133号",
                "category": "房产小区:商务楼宇",
                "location": {
                    "lat": 37.468609,
                    "lng": 121.44223
                },
                "ad_info": {
                    "adcode": "370613",
                    "province": "山东省",
                    "city": "烟台市",
                    "district": "莱山区"
                },
                "_distance": 167.2,
                "_dir_desc": "南"
            }
        ]
    }
}
2 回复
NutMap nm = Json.fromJson(NutMap.class, content);
NutMap result  = nm.getAs("result", NutMap.class);

感谢wendal,生活因nutz而更加美好!.

添加回复
请先登陆
回到顶部