简体   繁体   中英

Sort Dictionary of Array Using Predicate

I have a json dictionary

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

I need to get all values of key allquestions in single array using predicate.

I have tried so far is

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

What will be the value of someValue to solve my problem?

Not entirely sure what your trying to achieve. If you want a list of all of the questions in that dictionary then iterate through each dictionary separately and then the same for the questions. Add the questions to an array and then filter that array. Not tried this code out but it's a start.

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]; 
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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