嵌套字典-定位单个键
|
我很高兴在这里有很多这类问题,但是我找不到可行的答案。
简而言之,我需要获取选定类别中所有产品的价格数组。
这是我的pList:
<key>Product Category</key>
<dict>
<key>Product 1</key>
<dict>
<key>Image</key>
<string></string>
<key>Large Image</key>
<string></string>
<key>Detail</key>
<string></string>
<key>Price</key>
<integer>100</integer>
</dict>
<key>Product 2</key>
<dict>
<key>Image</key>
<string></string>
<key>Large Image</key>
<string></string>
<key>Detail</key>
<string></string>
<key>Price</key>
<integer>200</integer>
</dict>
</dict>
我不知道如何在这样的层次结构中定位目标。到目前为止,这是我的尝试:
NSString *detailPListPath = [[NSBundle mainBundle] pathForResource:@\"detail\" ofType:@\"plist\"];
NSDictionary *detailDictionary = [NSDictionary dictionaryWithContentsOfFile:detailPListPath];
currentDetail = [[NSMutableArray alloc] init];
for (id object in [detailDictionary objectForKey:indication]) {
[currentDetail addObject:object];
}
但是then2ѭ仅显示产品1,产品2等。
谢谢你的尽心帮助!
没有找到相关结果
已邀请:
1 个回复
涸坍饺
的快速枚举会遍历键,因此需要将键添加到数组中。因此,您的输出显示产品1,产品2等。 我需要获取一系列价格 所选类别中的所有产品。 您需要使用以下键(产品1,产品2等)来检索关联的产品字典,然后检索与价格键关联的值:
请记住,结果
没有特定顺序。