我有一个看起来像这样的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]);
答案 0 :(得分:2)
根据上面的plist,您可以访问country
的值:
NSDictionary* record2 = (NSDictionary*)[dict objectForKey:key2];
NSString* country = (NSString*)[record2 objectForKey:@"country"];
答案 1 :(得分:-1)
看起来像XML看到http://en.wikipedia.org/wiki/XML有很多解析,我打赌iDevices在他们的SDK中有一个