簡體   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