繁体   English   中英

使用谓词对数组的字典进行排序

[英]Sort Dictionary of Array Using Predicate

我有一个json字典

[
  {
    "allquestions": [
      {
        "question": "First question in 0th index"
      },
      {
        "question": "Second  question in 0th index"
      }
    ]
  },
  {
    "allquestions": [
      {
        "question": "First  question in 1st index"
      }
    ]
  }
]

我需要使用谓词来在单个阵列关键allquestions的所有值。

我到目前为止已经尝试过

NSPredicate *combinePagePredicate = [NSPredicate predicateWithFormat:@"allquestions == %@",@"someValue"];

someValue解决我的问题的价值是什么?

不确定您要达到的目标。 如果要获取该词典中所有问题的列表,请分别遍历每个词典,然后对这些问题进行相同的遍历。 将问题添加到数组,然后过滤该数组。 没有尝试过此代码,但这是一个开始。

NSMutableArray *questions = [[NSMutableArray alloc] init]; 
for (id i in dictionaryArray)
{
    NSArray *arr = i[@"allquestions"];
    for (id x in arr) 
    {
       NSString *currentQuestion = [x objectForKey:@"question"];
       [questions addObject:currentQuestion]; 
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM