NSPredicate为内联键的数组

我有一个在以下格式的字典数组

[ { "student": { "id": "1", "studentUserDetail": { "firstName": "Bonny", "lastName": "Roby" } } }, { "student": { "id": "1", "studentUserDetail": { "firstName": "Bonny", "lastName": "Kety" } } }, { "student": { "id": "1", "studentUserDetail": { "firstName": "Arther", "lastName": "Fone" } } }, ] 

在上面的数组中,我需要在内部键student.StudentUserDetails.firstName中过滤包含serachKey(例如Bonny)的所有元素。 我如何过滤使用NSPredicate

 NSString *name = @"Bonny"; NSPredicate *pred = [NSPredicate predicateWithFormat: @"student.studentUserDetail.firstName == %@", name]; NSArray *arr = [self.anArray filteredArrayUsingPredicate:pred]; NSLog(@"Bonny found at : %@", arr); 

编辑:

如果你想基于一个模式进行search,那么使用:

 NSPredicate *pred = [NSPredicate predicateWithFormat: @"student.studentUserDetail.firstName beginswith[cd] %@", name]; 
 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]; 
 NSPredicate *filter = [NSPredicate predicateWithFormat:@"student.studentUserDetail.firstName CONTAINS[cd] %@ ", searchString]; 

为我完美工作