ios - 如何在 iOS 中解析 mapquest geocode JSON

标签 ios json parsing nsdictionary mapquest

我正在尝试解析来自 Mapquest geocode 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。我的解析方式是否正确?

最佳答案

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

关于ios - 如何在 iOS 中解析 mapquest geocode JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17821227/

相关文章:

Python解析一个巨大的文件

ios - 如何逐像素绘制圆圈?

UiView 中的 IOS swift avplayer 我怎样才能让它工作

php - 如何使用PHP解析Excel文件

sql - 在 Redshift 中使用 json_extract_path_text 时如何跳过错误?

asp.net - 向 Web API 响应添加额外的 JSON 对象

javascript - 正则表达式查找一段代码中的所有方法

ios - 如何在 swift 4 的 UILabel 中找到子字符串的框架?

C++ Mac Xcode : Undefined symbols for architecture x86_64:

java - jackson 1.9.x 使用自定义注释进行反序列化