objective-c - 获取多维字典的所有键

标签 objective-c dictionary

我有一本像这样的字典:

{
dataTypes =     (
            {
        dataType = "datatype1";
        editable = 1;
        maxValue = 300;
        minValue = 0;
        order = 1;
        title = "Title 1";
        type = numeric;
        units = kg;
    },
            {
        dataType = "datatype 2";
        editable = 1;
        maxValue = 300;
        minValue = 0;
        order = 2;
        title = "title2";
        type = numeric;
        units = gm;
    },
            {
        dataType = "datatype3";
        editable = 1;
        maxValue = 300;
        minValue = 20;
        order = 3;
        title = "title3";
        type = numeric;
        units = kg;
    }
);
name = "Name";
order = 1
title = "Title";
}

我想获取这个字典中的所有键。

我尝试了 [myDict allKeys],但是这只返回了四个键:DataTypesnameorder标题

我想检索所有键:dataTypeeditablemaxvalue 等。

最佳答案

试试这个。

NSArray *tempArray = [myDict objectForKey:@"dataTypes"];

NSDictionary *tempDictionary = (NSDictionary *)tempArray[0];

[tempDictionary allKeys] 将有你想要的。

写这个方法。

- (NSDictionary *)dictionaryFromArrayWithinDictionary:(NSDictionary *)dictionary withKey:(NSString *)key{
    NSArray *tempArray = [dictionary objectForKey:key];
    return (NSDictionary *)tempArray[0]; 
}

这将返回内部字典,只需对该字典调用“allKeys”,您将获得所需的所有键。

关于objective-c - 获取多维字典的所有键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34939463/

相关文章:

ios - UITableViewCell 内部的 UIPageViewController

iphone - 指定的权利...配置文件。 (0xE8008016)。错误 iOS 4.2

ios - 无法将排序的字典序列化为 JSON - Swift 3

python - 根据匹配多个键组合列表中的字典:value pairs

python - 字典键数

ios - 从不同单元格的详细 View 访问标签数据(我使用核心数据)

ios - 尽可能压缩UIImage?

dictionary - 检测映射中的键是否存在结构

python - Rpy2:如何将字典列表转换为 R 数据框

iphone - Objective-C 排序字符串日期数组