1

我正在尝试解析来自 Mapquest 地理编码 API 的 JSON 结果。

NSDictionary *JSONReponseDic = [NSJSONSerialization JSONObjectWithData:mapquestdata options:0 error:&error];
NSMutableArray *resultsArray = [JSONReponseDic objectForKey:@"results"];

NSDictionary *locationDic = [resultsArray objectAtIndex:0];
NSLog(@"loc dic %@", locationDic);

NSString *city = [locationDic objectForKey:@"adminArea5"];
NSLog(@"city : %@", city);

我可以解析直到 locationDic,它返回

loc dic {
locations =     (
            {
        adminArea1 = US;
        adminArea1Type = Country;
        adminArea3 = CA;
        adminArea3Type = State;
        adminArea4 = "Santa Clara County";
        adminArea4Type = County;
        adminArea5 = "Los Altos";
        adminArea5Type = City;
        displayLatLng =             {
            lat = "37.37964";
            lng = "-122.11877";
        };
        dragPoint = 0;
        geocodeQuality = POINT;
        geocodeQualityCode = P1AAA;
        latLng =             {
            lat = "37.37949";
            lng = "-122.11903";
        };
        linkId = 0;
        mapUrl = "http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luub206tl1,rg=o5-9ubah0&type=map&size=225,160&pois=purple-1,37.37949,-122.11903,0,0|&center=37.37949,-122.11903&zoom=15&rand=-159915059";
        postalCode = "94022-2707";
        sideOfStreet = R;
        street = "145 1st St";
        type = s;
    }
);
providedLocation =     {
    location = "145 1st St,Los Altos, CA 94022";
};
}

然后,当我尝试获取城市名称时,日志返回 null。我以正确的方式解析这个吗?

4

1 回答 1

2

应该是[locationDic valueForKeyPath:@"locations.adminArea5"];

于 2013-07-23T21:16:53.067 回答