2011-12-21 59 views
0

我的plist是象下面這樣:在數組字典中選擇項目?

<array> 
    <dict> 
     <key>eye</key> 
     <string>eye_man_blue</string> 
     <key>lips</key> 
     <string>lips_blue</string> 
    </dict> 
    <dict> 
     <key>eye</key> 
     <string>eye_man</string> 
     <key>lips</key> 
     <string>lips</string> 
    </dict> 
</array> 

,我需要選擇/讀 「eye_man_blue」 forkey:眼睛atIndex:0。 這意味着,如果我做NSLog(@「%@。png」,eyeDisplay);
它想記錄:eye_man_blue.png
我想是這樣:

arrayItems=[NSMutableArray arrayWithContentsOfFile:finalPath]; 
NSArray *itemArray = [NSArray arrayWithObjects:[arrayItems objectAtIndex:0], nil]; 
NSDictionary *itemdict = [NSDictionary dictionaryWithObject:itemArray forKey:@"eye"]; 
NSLog(@"%@",itemdict); 

我得到:

2011-12-21 11:00:30.749 project[358:f803] { 
    eye =  (
    ); 
} 

回答

1

你有1個陣列2個索引,每個索引是一本字典。

arrayItems=[NSMutableArray arrayWithContentsOfFile:finalPath]; 
NSString *myString = [[arrayItems objectAtIndex:0] objectForKey:@"eye"]; 
NSLog (@"%@.png",myString); 
+0

自動引用計數的問題:對於選擇沒有已知的實例方法「forKey:」我 – Albert 2011-12-21 03:24:51

+0

更新我的代碼是'objectForKey:' – syclonefx 2011-12-21 03:26:48

+0

工作一樣的魅力 – Albert 2011-12-21 03:41:49