1

在我的应用程序中,我得到了 MutableDictionary 中的数据,如下所示,

 ApproverDetails:(
    {
    "APPROVER_ID" = "5000";
    "APPROVER_USER_NAME" = "38400 user";
    "END_DATE" = "12/29/10";
    "START_DATE" = "12/14/10";
    "SUBSTITUTE_ID" = SUPERVISOR;
    "SUBSTITUTE_USER_NAME" = "ACCESS ONLY";
    },
    {
    "APPROVER_ID" = "6000";
    "APPROVER_USER_NAME" = "ACCESS ONLY";
    "END_DATE" = "12/31/10";
    "START_DATE" = "12/15/10";
    "SUBSTITUTE_ID" = SSEEMON;
    "SUBSTITUTE_USER_NAME" = "Sunil Seemon";
    },
    {
    "APPROVER_ID" = "7000";
    "APPROVER_USER_NAME" = mit;
    "END_DATE" = "11/22/10";
    "START_DATE" = "11/09/10";
    "SUBSTITUTE_ID" = 2000;
    "SUBSTITUTE_USER_NAME" = mitul;
   }
 )

从上面的字典中,我希望通过以“ACC”开头的键“Approved_User_Name”来分叉数据

并将分叉的数据放入其他数组。

请建议我该怎么做?

4

2 回答 2

2

您可以使用 NSPredicate 获取数据,如下所示:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"APPROVER_USER_NAME BEGINSWITH[cd] ACC"];
searchResults = [[ApproverDetails filteredArrayUsingPredicate:predicate] mutableCopy];
于 2012-10-08T06:15:19.300 回答
1

试试这个

NSMutableArray *bifurcateArray=[[NSMutableArray alloc]initWithArray:nil];
for (NSDictionary *temp in ApproverDetails) {
    NSString *string=[temp objectForKey:@"APPROVER_USER_NAME"];
    if ([string rangeOfString:@"ACC"].location!=NSNotFound && [string rangeOfString:@"ACC"].location==0 ) {
        [bifurcateArray addObject:temp];
    }
}
NSLog(@"bifurcated data : %@",bifurcateArray);
于 2012-10-08T06:18:40.050 回答