ios - NSPredicate 转化为深度过滤值

标签 ios search nsarray nsdictionary nspredicate

我有以下多个数据列表,我想过滤掉男性 使用 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);

Humans.json文件

关于ios - NSPredicate 转化为深度过滤值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16806992/

相关文章:

ios - xamarin 表单应用程序图标文本在 ios 上没有空格

xml - 使用 XPATH 搜索包含的文本

ios - 使用 NSArray 中的数据检查 NSString 的内容

objective-c - 将 NSString 转换为字符数组

ios - 使用自定义按钮重新排序 tableview 单元格

ios - 重命名 View Controller 后 xcode iOS 应用程序崩溃

java - 将字符(欧洲)扩展为美国 ascii,用于搜索索引

iphone - 当我把自己放进去时,NSArray 失去了值(value)

ios - 在 host_processor_sets swift 3 上出现错误

hadoop - 如何配置Cloudera Search以与Impala一起使用?