从字典数组中删除键值的重复项

我正在做一个Facebook API请求,让我从一个特定的Facebook组中的所有专辑名称。 我得到一个有3个键/值的字典数组,其中一个是映射到专辑名称的关键“名称”,以及键“id”和“created_time”。

唯一的问题是,由于某种原因,我收回了相册的重复“名称”值…但只有一对夫妇。 而当我去Facebook页面时,这张专辑只有一个实例,没有重复。

此外,他们的“ID”值是不同的,但它只是从重复组中的第一个字典,有一个Facebook的ID实际上指向有效的数据,其他Facebook的ID值只是不会返回任何东西,当你执行一个Facebook图与他们一起search,所以这是我想要的第一个重复。

我怎样才能从我的数组中删除这些无用的重复字典,并保持有效的Facebook的ID? 谢谢! 🙂

首先我想说的是,从脸书上find一个“干净的”清单,而不是在之后掩盖问题,这样做可能会更有益处。 这现在可能是不可能的,但至less要弄清楚这个行为的原因是什么,或者提交一个错误报告。

除此之外,这应该做的伎俩:

-(NSMutableArray *) groupsWithDuplicatesRemoved:(NSArray *) groups { NSMutableArray * groupsFiltered = [[NSMutableArray alloc] init]; //This will be the array of groups you need NSMutableArray * groupNamesEncountered = [[NSMutableArray alloc] init]; //This is an array of group names seen so far NSString * name; //Preallocation of group name for (NSDictionary * group in groups) { //Iterate through all groups name =[group objectForKey:@"name"]; //Get the group name if ([groupNamesEncountered indexOfObject: name]==NSNotFound) { //Check if this group name hasn't been encountered before [groupNamesEncountered addObject:name]; //Now you've encountered it, so add it to the list of encountered names [groupsFiltered addObject:group]; //And add the group to the list, as this is the first time it's encountered } } return groupsFiltered; }