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

如果值包含“文本”,我需要过滤掉所有字典中的任何键

4

2 回答 2

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");
        }
    }
}
于 2013-10-15T05:43:28.523 回答
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];
}
于 2013-10-15T05:29:00.063 回答