gpt4 book ai didi

ios - NSPredicate用于字典数组中的内键

转载 作者:行者123 更新时间:2023-12-01 17:29:35 24 4
gpt4 key购买 nike

我有以下格式的字典数组

    [
{
"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);

编辑:

如果要基于模式搜索,请使用:
NSPredicate *pred = [NSPredicate predicateWithFormat:
@"student.studentUserDetail.firstName beginswith[cd] %@", name];

关于ios - NSPredicate用于字典数组中的内键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34441282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com