我有一本像这样的字典:
{
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]
,但是这只返回了四个键:DataTypes
、name
、order
,标题
。
我想检索所有键:dataType
、editable
、maxvalue
等。
最佳答案
试试这个。
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/