我有以下多个数据列表,我想过滤掉男性 使用 NSPredicate 我该怎么做
[
"Human": {
"Person": {
"isMale": true,
"name": "PersonA",
"id": "100"
},
"isCheck": true
},
"Human": {
"Person": {
"isMale": false,
"name": "PersonB",
"id": "200"
},
"isCheck": false
},
.
.
.
.
]
一个数组包含字典,每个字典包含一个人的字典,我想过滤掉内部字典的人键。 任何帮助将不胜感激。
最佳答案
Wain's answer会工作正常。
试试这个代码片段,它使用根据您的问题形成的 json 文件。
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"Humans" ofType:@"json"];
NSData *data = [[NSData alloc]initWithContentsOfFile:filePath];
NSArray *users = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Human.Person.isMale == %@",@true];
NSArray *filteredArray = [users filteredArrayUsingPredicate:predicate];
NSLog(@"%@",filteredArray);
关于ios - NSPredicate 转化为深度过滤值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16806992/