我有一個plist中,看起來像這樣:如何從字典中讀出數據?
<dict>
<key>Aaron</key>
<dict>
<key>number</key>
<string>1234</string>
<key>country</key>
<string>Spanien</string>
<key>year</key>
<string>1989</string>
</dict>
<key>Abagail</key>
<dict>
<key>number</key>
<string>1234</string>
<key>country</key>
<string>Frankrike</string>
<key>year</key>
<string>2001</string>
</dict>
<key>Abbey</key>
<dict>
<key>number</key>
<string>1289</string>
<key>country</key>
<string>Tyskland</string>
<key>year</key>
<string>2009</string>
</dict>
有了這個代碼,我得到每個對象的關鍵:
NSLog(@"test %@", [dict objectForKey:key2]);
我怎樣才能得到每個字符串值目的。我viewDidLoad中看起來像這樣
NSString *path = [[NSBundle mainBundle] pathForResource:@"vin"
ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:path];
self.allNames = dict;
NSString *key2 = viewTitle;
NSLog(@"test %@", [dict objectForKey:key2]);
這個問題不清楚,你是否真的成功讀取文件? – borrrden 2012-04-03 13:51:02
爆炸地鐵隧道讓我雙重評論。 – borrrden 2012-04-03 13:52:03
是的,我可以讀出文件。 – user1301000 2012-04-03 14:30:48