过滤字典的NSMutableArray,在Objective-C中具有确切的int字典值

问题描述 投票:0回答:1

我有一个包含nsdictionary对象的NSMutableArray。

`[
    {
        "IId": 0,
        "BookSLNo": 0,
        "RollNoOrEmpId": "0",
        "BatchId": 38,
        "Batch": "NA",
        "UserId": 20,
        "Name": "Kaiser Ahmed Khan",
        "NickName": "",
        "GenderId": 1,
        "Gender": "Male",
        "DateOfBirth": "01/Jan/2000",
        "DateOfBirthYMD": "20000001",
        "DesignationId": 8,
        "Designation": "Extra Assistant Commissioner of Taxes",
        "ZoneId": 12,
        "Zone": "Taxes Appeal Zone-1 Dhaka",
        "RangeId": 15,
        "Range": "NA",
        "Circle": "0",
        "WorkingDistrictId": 13,
        "WorkingDistrict": "Dhaka",
        "HighestDegree": "",
        "SubjectName": "",
        "University": "",
        "BloodGroupId": "1",
        "BloodGroup": "NA",
        "FatherName": "",
        "MotherName": "",
        "MarriageDate": "/Date(946713600000)/",
        "SpouseName": "",
        "SpouseBloodGroupId": "0",
        "SpouseBloodGroup": "",
        "SpouseProfession": "",
        "Child1Name": "",
        "Child1GenderId": 0,
        "Child1Gender": "",
        "Child2Name": "",
        "Child2GenderId": 0,
        "Child2Gender": "",
        "Child3Name": "",
        "Child3GenderId": 0,
        "Child3Gender": "",
        "ParmHouseNo": "",
        "ParmStreetNo": "",
        "ParmPostOffice": "",
        "ParmThana": "",
        "ParmDistrictId": 12,
        "ParmDistrict": "Cox's Bazar",
        "PresHouseNo": "",
        "PresStreetNo": "",
        "PresPostOffice": "",
        "PresThana": "",
        "PresDistrictId": 0,
        "PresDistrict": "",
        "ResidentialPhone": "",
        "Mobile": "01711372588",
        "EMailId": "[email protected]",
        "FacebookId": "",
        "SkypeId": "",
        "JoiningDate": "01/Jan/2007",
        "FirstJoinedAsId": 0,
        "FirstJoinedAs": "",
        "Picture": null,
        "PictureFamily": null,
        "UserGroupId": 2,
        "UserGroup": null,
        "SectionId": 1,
        "Section": null,
        "DepartmentId": 1,
        "Department": null,
        "CreateDate": "/Date(1573221227000)/",
        "CreatedBy": 0,
        "ModifyDate": "/Date(-62135568000000)/",
        "ModifyBy": 0,
        "ExecuteType": null,
        "PresAddress": ",,,,,,,",
        "PictureUrl": "http://taxdirectorybd.com/upload/UserImages/Profile/20.jpg",
        "PictureFamilyUrl": "http://taxdirectorybd.com/upload/UserImages/Wal/20.jpg",
        "JoiningDateYMD": "01/Jan/2007",
        "MarriageDateSTR": "01/01/2000",
        "IsFreedomFighter": null,
        "Others": null
    },
    {
        "IId": 0,
        "BookSLNo": 0,
        "RollNoOrEmpId": "0",
        "BatchId": 38,
        "Batch": "NA",
        "UserId": 21,
        "Name": "Nasreen Ara",
        "NickName": "",
        "GenderId": 2,
        "Gender": "Female",
        "DateOfBirth": "01/Jan/2000",
        "DateOfBirthYMD": "20000001",
        "DesignationId": 8,
        "Designation": "Extra Assistant Commissioner of Taxes",
        "ZoneId": 12,
        "Zone": "Taxes Appeal Zone-1 Dhaka",
        "RangeId": 15,
        "Range": "NA",
        "Circle": "0",
        "WorkingDistrictId": 13,
        "WorkingDistrict": "Dhaka",
        "HighestDegree": "",
        "SubjectName": "",
        "University": "",
        "BloodGroupId": "1",
        "BloodGroup": "NA",
        "FatherName": "",
        "MotherName": "",
        "MarriageDate": "/Date(946713600000)/",
        "SpouseName": "",
        "SpouseBloodGroupId": "0",
        "SpouseBloodGroup": "",
        "SpouseProfession": "",
        "Child1Name": "",
        "Child1GenderId": 0,
        "Child1Gender": "",
        "Child2Name": "",
        "Child2GenderId": 0,
        "Child2Gender": "",
        "Child3Name": "",
        "Child3GenderId": 0,
        "Child3Gender": "",
        "ParmHouseNo": "",
        "ParmStreetNo": "",
        "ParmPostOffice": "",
        "ParmThana": "",
        "ParmDistrictId": 0,
        "ParmDistrict": "",
        "PresHouseNo": "",
        "PresStreetNo": "",
        "PresPostOffice": "",
        "PresThana": "",
        "PresDistrictId": 0,
        "PresDistrict": "",
        "ResidentialPhone": "",
        "Mobile": "01552371912",
        "EMailId": "[email protected]",
        "FacebookId": "",
        "SkypeId": "",
        "JoiningDate": "01/Jan/2000",
        "FirstJoinedAsId": 0,
        "FirstJoinedAs": "",
        "Picture": null,
        "PictureFamily": null,
        "UserGroupId": 2,
        "UserGroup": null,
        "SectionId": 1,
        "Section": null,
        "DepartmentId": 1,
        "Department": null,
        "CreateDate": "/Date(1573221354000)/",
        "CreatedBy": 0,
        "ModifyDate": "/Date(-62135568000000)/",
        "ModifyBy": 0,
        "ExecuteType": null,
        "PresAddress": ",,,,,,,",
        "PictureUrl": "http://taxdirectorybd.com/upload/UserImages/Profile/21.jpg",
        "PictureFamilyUrl": "http://taxdirectorybd.com/upload/UserImages/Wal/21.jpg",
        "JoiningDateYMD": "01/Jan/2000",
        "MarriageDateSTR": "01/01/2000",
        "IsFreedomFighter": null,
        "Others": null
    }
    ]

我正在尝试使用键UserId过滤数组。但是无法过滤。我以这种方式尝试过。

NSString* userId=userInfo[@"UserId"];
NSPredicate* predicate=[NSPredicate predicateWithFormat:@"(UserId == %@)",userId];  NSArray* filteredArrays = [allData filteredArrayUsingPredicate:predicate];

此处UserId包含字符串格式的整数值。尝试使用提供的代码段进行过滤时,它总是返回O对象。

objective-c filtering nsmutablearray nsdictionary nspredicate
1个回答
0
投票
您无法将字符串与类似的数字进行比较。因此,只需采用intValue并将其作为int进行比较。

NSString *userId = userInfo[@"UserId"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UserId = %d", userId.intValue]; NSArray *filtered = [allData filteredArrayUsingPredicate:predicate];

© www.soinside.com 2019 - 2024. All rights reserved.