1

如何在 plist 文件中的字典中访问字典中的字符串?我试过这个但它不起作用:

NSString *myfile = [[NSBundle mainBundle] pathForResource: arrayname ofType:@"plist"];
WordsDic = [[NSDictionary alloc] initWithContentsOfFile:myfile];

words = [WordsDic allKeys];

insidedic = [[NSDictionary alloc] initWithDictionary:[[words objectAtIndex:0] ]];;
level2 = [insidedic allKeys];

然后我尝试了这个但我得到了一个错误

for (NSString *parent in words) {

        insidedic = [WordsDic objectForKey:parent];
        level2 = [insidedic allKeys];

        NSLog(@"%@", level2);
    }
4

1 回答 1

1

您可以尝试以下方法:

for (NSString *key in [wordsDic allKeys]) {
   NSDictionary *secondLevel = [wordsDic objectForKey:key];
   for (NSString *secondLevelKey in [secondLevel allKeys]) {
      NSLog(@"%@",[secondLevel objectForKey:secondLevelKey]);
   }
}

在您的代码中,“level2”是一个数组,而不是一个字符串,因此会因 NSLog 语句而崩溃。

于 2012-08-29T15:22:42.320 回答