我有一个NSDictionary,其中包含一个NSDictionary,该NSDictionary也包含NSDictionaries。现在,只有我拥有网站时,我就有了提取所需内容的代码。这是我的代码。
NSInteger selectedRow = [self.myTableView selectedRow];
NSString *currentName = [self.theFullArray objectAtIndex:selectedRow];
NSMutableArray *theOriginalArray = [self.theDictionary.allKeys mutableCopy];
if ([self.theDictionary.allKeys containsObject:@"#"]) {
[theOriginalArray removeObject:@"#"];
}
NSMutableArray *sortedKeys = [[theOriginalArray sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES]]] mutableCopy];
if ([self.theDictionary.allKeys containsObject:@"#"]) {
[sortedKeys addObject:@"#"];
}
NSArray *theFullDictObjects = sortedKeys;
NSUInteger theFullDictCount = [theFullDictObjects count];
NSDictionary *currentInfo = nil;
int firstI = 0;
while (firstI < theFullDictCount) {
NSString *currentFullDictObject = [theFullDictObjects objectAtIndex:firstI];
NSDictionary *theSubDict = [self.theDictionary objectForKey:currentFullDictObject];
NSArray *theSubDictObjects = [theSubDict allKeys];
NSUInteger theSubDictCount = [theSubDictObjects count];
int secondI = 0;
while (secondI < theSubDictCount) {
NSString *currentDictObject = [theSubDictObjects objectAtIndex:secondI];
if ([currentName isEqualToString:currentDictObject]) {
NSDictionary *theDict = [theSubDict objectForKey:currentDictObject];
currentInfo = theDict;
break;
}
secondI++;
}
if (currentInfo) {
break;
}
firstI++;
}
NSLog(@"currentInfo: %@", currentInfo);
现在这有效,但是当您的NSDictionaries列表很大时,它有点慢。是否有另一个代码可以更有效地执行此操作。
因此,假设我的值是“ www.adobe.com”,那么我如何获得
<dict>
<key>Name</key>
<string>Adobe</string>
<key>Website</key>
<string>www.adobe.com</string>
<key>Sub Category</key>
<string>Technology</string>
<key>Category</key>
<string>Account</string>
<key>PRLCountry</key>
<string>Belgium</string>
</dict>
如果您查看图片,可以看到字典的构建方式。
谢谢。