【发布时间】:2014-02-13 22:06:25
【问题描述】:
我必须管理这个丑陋的 xml 结构。 如何查询所有以/包含“Key”开头的 Key-Tag?
Xml-结构:
<Data>
<Rec>
<Key1>0001</Key1>
<Key2>0015</Key2>
<Key3>0002</Key3>
<Key4>0022</Key4>
...
</Rec>
<Rec>
<Key1>0015</Key1>
<Key2>0022</Key2>
<Key3>0002</Key3>
<Key4>0001</Key4>
...
</Rec>
...
</Data>
Rec-Object-Structure:
@interface Rec : NSObject
@property (nonatomic, copy) NSMutableDictionary *content;
@end
这是我在 Key1 上选择的代码:
predicateRecs = [NSPredicate predicateWithFormat:@"content.%K == %@", @"Key1", @"0001"];
[result addObjectsFromArray:[recs filteredArrayUsingPredicate: predicateRecs]];
recs 是一种 NSArray 类型,包含 Rec - 对象。
%K 需要能够执行以下操作:content.@allKeys BEGINSWITH %@ == %@,@"Key", @"0001"`
我想获取所有具有值的键,例如0001 我该怎么做?
谢谢
【问题讨论】:
-
您的“代码”sn-p 中的“
**recs**”位是否正确? -
不,它应该只是粗体。我已经修好了。
-
你试过了吗:
predicateRecs = [NSPredicate predicateWithFormat:@"@allValues == %@", @"0001"]; -
@Lefteris:它对我不起作用。请记住,我想从 NSDictionary 中获取所有项目,其中所有 NSDictionary-Keys 都以“Key”开头并具有例如值“0001”。在这种情况下,结果应该是:
[Key1][0001]和[Key4][0001]。我想它需要查询类似的东西,其中 Key 有一种 * Placeholder:[NSPredicate predicateWithFormat:@"content.%K == %@", @"Key*", @"0001"];
标签: ios objective-c ios7 nsdictionary nspredicate