查询plist是一个字典数组

我有一个拥有一系列字迹的plist。 在字典中有一个名为UID的KEY。 我想查询哪里UID =“1234”plist ..我将如何search?

样品

<array> <dict> <key>UID</key> <string>1234</string> <key>name</key> <string>bob</string> </dict> .... </array> 

在plist中读入一个字典数组,然后在NSArray上使用filteredArrayUsingPredicate:方法:

 NSString *path = [[NSBundle mainBundle] pathForResource:@"MyInfo" ofType:@"plist"]; NSArray *plistData = [NSArray arrayWithContentsOfFile:path]; NSPredicate *filter = [NSPredicate predicateWithFormat:@"UID = %d", 1234]; NSArray *filtered = [plistData filteredArrayUsingPredicate:filter]; NSLog(@"found matches: %@", filtered); 

在plist中读入一个字典数组,然后使用NSDictionary的objectForKey:方法。

 NSString *path = [[NSBundle mainBundle] pathForResource:@"MyInfo" ofType:@"plist"]; NSArray *plistData = [[NSArray arrayWithContentsOfFile:path] retain]; for (NSDictionary *dict in plistData) { if ([[dict objectForKey:@"UID"] isEqualToString:@"1234"]) { NSLog(@"Found it!"); } }