NSPredicate for inner key in array of dictonary

后端 未结 3 1036
温柔的废话
温柔的废话 2021-01-24 20:35

i have an array of dictionay in the following format

    [
 {
      \"student\": {
        \"id\": \"1\",

        \"studentUserDetail\": {
          \"firstName         


        
3条回答
  •  情话喂你
    2021-01-24 21:16

    NSArray *array = @[
                      @{
                         @"student": @{
                                 @"id": @"1",
                                 @"studentUserDetail": @{
                                         @"firstName": @"Bonny",
                                         @"lastName": @"Roby"
                             }
                         }
                         },
                      @{@"student": @{
                                @"id": @"1",
                                @"studentUserDetail": @{
                                        @"firstName": @"Bonny",
                                        @"lastName": @"Kety"
                                    }
                                }
                      },
                      @{
                         @"student": @{@"id": @"1",
                                       @"studentUserDetail": @{
                                               @"firstName": @"Arther",
                                               @"lastName": @"Fone"
                                               }
                                       }
                      }];
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(student.studentUserDetail.firstName) == %@", @"Bonny"];
    NSArray *newArray = [array filteredArrayUsingPredicate:predicate];
    

提交回复
热议问题