使用密钥从nsdiscionary中删除重复的数据集

时间:2013-11-27 06:33:54

标签: ios iphone objective-c nsdictionary

<__NSArrayM 0x82701fe0>(
{
    Distance = "2.08";
    address = Manjalpur;
    dob = "09-04-1986 ";
    email = "kan@t.com";
    facebookid = "";
    fname = kanan;
    gender = Female;
    imageurl = "https://foursquare.com/img/categories_v2/food/indian_";
    lastlogin = "/Date(1378288646803+0000)/";
    latitude = "22.27052139756";
    lname = kanan;
    longitude = "73.196614980698";
    name = "Green Chillies";
    photopath1 = "";
    time = "/Date(1378288744627+0000)/";
    userid = 202;
},
{
    Distance = "2.08";
    address = Manjalpur;
    dob = "09-04-1986 ";
    email = "kan@t.com";
    facebookid = "";
    fname = kanan;
    gender = Female;
    imageurl = "https://ss1.4sqi.net/img/categories_v2/food/indian_";
    lastlogin = "/Date(1378288646803+0000)/";
    latitude = "22.27052139756";
    lname = kanan;
    longitude = "73.196614980698";
    name = "Green Chillies";
    photopath1 = "";
    time = "/Date(1378288744627+0000)/";
    userid = 202;
},
{
    Distance = "2.12";
    address = Manjalpur;
    dob = "03-11-1983";
    email = "r@tax.com";
    facebookid = 100001835956323;
    fname = Rohan;
    gender = Female;
    imageurl = "https://foursquare.com/img/categories_v2/building/apartment_";
    lastlogin = "/Date(1385115357020+0000)/";
    latitude = "22.270002988846";
    lname = Panchal;
    longitude = "73.197391863176";
    name = "Tulsidham circle";
    photopath1 = "http://taxsmart.in/FTP_Data/S55_2.jpg";
    time = "/Date(1381412082083+0000)/";
    userid = 55;
},
{
    Distance = "2.12";
    address = Manjalpur;
    dob = "03-11-1983";
    email = "r@tax.com";
    facebookid = 100001835956323;
    fname = Rohan;
    gender = Female;
    imageurl = "https://ss1.4sqi.net/img/categories_v2/building/apartment_";
    lastlogin = "/Date(1385115357020+0000)/";
    latitude = "22.270002988846";
    lname = Panchal;
    longitude = "73.197391863176";
    name = "Tulsidham circle";
    photopath1 = "http://taxsmart.in/FTP_Data/S55_2.jpg";
    time = "/Date(1381412082083+0000)/";
    userid = 55;
}

  • 我的 NSDictionary * finalResult 打印此结果
  • 实际上只有两条记录,但是我得到的是网络服务 由于独特的图像,这种类型的结果无法区分。

  • 所以如何删除重复的数据集。相同的用户数据只有关键图像才有所不同。

  • 我只想要用户的单一记录与哪一个(任何一个)无关。所以最后我只会得到两个记录

2 个答案:

答案 0 :(得分:1)

//你可以像这样过滤你的回复:

// tempArray是内容webservice响应

的数据数组
NSMutableArray *mainArray = [[NSMutableArray alloc]init];
for (int i = 0; i< [temprray count]; i ++) {
    if ([mainArray count]==0) {
        [mainArray addObject:[temprray objectAtIndex:0]];
    }
    else {

        NSDictionary *tempDict = [temprray objectAtIndex:i];
        BOOL isRecordFound = NO;
        for (int j = 0; j < [mainArray count]; j++) {
            NSDictionary *tempinnerDict = [mainArray objectAtIndex:j];
            if ([[tempinnerDict valueForKey:@"userid"] integerValue] == [[tempDict valueForKey:@"userid"] integerValue]) {
                isRecordFound = YES;
                break;
            }
        }
        if (!isRecordFound) {
            [mainArray addObject:tempDict];
        }
    }
}

答案 1 :(得分:0)

这可能是网络服务错误。最好的方法是联系网络团队,或者您可以使用以下方式删除重复项

您可以使用以下方法检查重复的字典

- (BOOL)isEqualToDictionary:(NSDictionary *)otherDictionary

在for循环中,您可以检查重复项,如果有人,可以使用

NSMutableArray 中删除它
- (void)removeObjectAtIndex:(NSUInteger)index