查询plist是一个字典数组 [英] Query plist that is an array of dictionary
本文介绍了查询plist是一个字典数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有一系列dicts的plist。在dict中有一个名为UID的KEY。我想查询plist,其中UID =1234..我将如何搜索?
I have a plist that has an array of dicts. in the dict there is a KEY with the name UID. I want to query the plist where UID="1234" .. how would I search?
sample
<array>
<dict>
<key>UID</key>
<string>1234</string>
<key>name</key>
<string>bob</string>
</dict>
....
</array>
推荐答案
将plist作为一组词典读入然后在 NSArray上使用
: filteredArrayUsingPredicate:
方法
Read in the plist as an array of dictionaries and then use filteredArrayUsingPredicate:
method on NSArray
:
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是一个字典数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文