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 に答える