2013-10-15 115 views
-1

我從服務器檢索數據的特定關鍵字,搜索功能是數據,低脂是字典等過濾字典的陣列包含

{ 
text : Some simple text, 
searchword : Apple text with new features, 
keyword : Normal words 
} 
{ 
text : Random, 
searchword : Newly generated text, 
keyword : Normal words 
} 
{ 
text : Some simple word, 
searchword : Latest version, 
keyword : Normal words 
} 

我需要過濾掉像任何陣列在所有的字典鍵,如果值包含「文本」

+0

你有什麼試試嗎? –

+0

想想吧! – Nassif

回答

0

你可以試試下面的代碼:

NSMutableArray *filteredArray = [NSMutableArray array]; 
for (NSDictionary *dictionary in initialArray) { 
    NSMutableDictionary *filteredDictionary = [NSMutableDictionary dictionary]; 

    [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 
     NSString *text = (NSString *)obj; 

     if ([text rangeOfString:@"text"].location == NSNotFound) { 
      [filteredDictionary addObject:obj forKey:key]; 
     } 
    }]; 

    [filteredArray addObject:filteredDictionary]; 
} 
0

那麼它是非常簡單的只是假設下面是你的詞典]數組: -

for (NSDictionary *dc in yourArr) 
{ 
    NSArray *yourArr)=[dc allValues]; 
    for (i=0; i<[arry count]; i++) 
    { 
     if ([[yourArr objectAtIndex:i] isEqualToString:@"text"]) 
     { 
      NSLog(@"found"); 
     } 
    } 
}