我有这样的字典:
<dict>
<key>ThemeName</key>
<string>Theme1</string>
<key>AddToFavoritesButton</key>
<dict>
<key>DownImage</key>
<string>heart_selected.png</string>
<key>UpImage</key>
<string>heart.png</string>
</dict>
<dict>
如何迭代所有键并获取数组中的所有值?
像这样:res[0] = Theme1
res[1] = heart_selected.png
res[2] = heart.png
...
由于
亨利
答案 0 :(得分:0)
这样的事情应该有效:
- (void)expandDictionary:(NSDictionary *)dict into:(NSMutableArray *)output
{
for(id key in [dict allKeys])
{
id value = [dict valueForKey:key];
if([value isKindOfClass:[NSDictionary class]])
{
[self expandDictionary:value into:output];
}
else
{
[output addObject:[value stringValue]];
}
}
}
- (NSArray *)expandDictionary:(NSDictionary *)dictionary
{
NSMutableArray *output = [NSMutableArray array];
[self expandDictionary:dictionary into:output];
return output;
}