Question

I am trying to parse the JSON result from Mapquest geocode API.

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);

I can parse until locationDic, which returns

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";
};
}

Then, when I am trying to get the city name, the log returns null. Am I parsing this the right way?

Was it helpful?

Solution

It should be [locationDic valueForKeyPath:@"locations.adminArea5"];.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top