objective-c - 从 nsarray 中取出对象

标签 objective-c ios xcode nsarray xcode4.3

我是 objective-c 的新手。我想从这个数组结果中取出几个对象,这些对象来自 JSON,我需要帮助。我如何从这个数组中取出对象?我怎样才能得到这些特征,然后是属性和路由名称等。

NSArray *directions=[jsonResult objectForKey:@"directions"];

    int i;
    NSArray *dict;
    int count = [directions count];
    for (i = 0; i < count; i++)
    {            
        NSLog (@"directions = %@", [directions objectAtIndex: i]);          
    }

The object that i want to get from

directions = {
features =     (
            {
        attributes =             {
            ETA = 1341190800000;
            length = 0;
            maneuverType = esriDMTDepart;
            text = "Start at 18304.680000,36152.730000";
            time = 0;
        };
        compressedGeometry = "+1+hrt+139j+0+0";
    },
            {
        attributes =             {
            ETA = 1341190800000;
            length = "1.43124650292492";
            maneuverType = esriDMTStraight;
            text = "Go southeast on PAN ISLAND EXPRESSWAY";
            time = "1.22675858855561";
        };
        compressedGeometry = "+1+hrt+139j+i9-a6+kp-bl";
    }
routeId = 1;
routeName = "18304.680000,36152.730000 - 29663.160389,40202.513760";
summary =     {
    envelope =         {
        spatialReference =             {
            wkid = 3414;
        };
        xmax = "29663.160018156";
        xmin = "18301.4360762186";
        ymax = "40229.9300290999";
        ymin = "35091.9900291003";
    };
    totalDriveTime = "24.8214824061658";
    totalLength = "17.2089251018779";
    totalTime = "24.8";
};

我该怎么做?

最佳答案

[directions objectAtIndex: i] 返回NSDictionary,如果要从中获取对象,执行以下操作

NSDictionary *dic = [directions objectAtIndex: i];
[dic valueForKey:@"routeName"] //route name
[dic valueForKey:@"routeId"] //routeId
[dic valueForKey:@"features"] //returns an nsdictionery too
[[dic valueForKey:@"features"] valueForKey:@"text"] //returns an nsdictionery too

等等

关于objective-c - 从 nsarray 中取出对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11293635/

相关文章:

objective-c - 如何模拟Cocoa的截图功能(Mac)?

ios - 在 ios Swift 中声明变量之间的区别?

ios - XCode 7 : How to assemble armv7, arm64 和 x86 .S 文件分开?

ios - 在 Swift 中追加字符串

iphone - 通过 Storyboard添加 subview 而不是手动添加 subview ?

ios - 没有主键的 MagicalRecord 导入

ios - 将 ios 框架(如 Google Maps API)添加到 subversion 将不允许正常结帐

ios - 尝试实现动态单元格高度时 TableView 抛出错误

ios - Xcode Bots 配置文件的位置

iphone - 应用程序退出后重新连接 XCode 调试控制台?