我试图在NSArray表单中过滤以下JSON对象示例。
[
{
"Name": "Andrew",
"Age": 28,
"Pets": [
{
"Name": "Domino"
},
{
"Name": "Sheldon"
}
]
},
{
"Name": "Matthew",
"Age": 26,
"Pets": [
{
"Name": "Shadow"
},
{
"Name": "Mojo"
}
]
}
]
我想过滤Pets.Name
包含字符串"Sha"
鉴于这个谓词,我希望结果匹配为:
[
{
"Name":"Matthew",
"Age":26,
"Pets":[
{
"Name":"Shadow"
}
]
}
]
这是一种简单的方法吗?
NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"Pets.Name == %@", searchText];
NSArray *temp = [MY_ARRAY filteredArrayUsingPredicate:filterPredicate];
答案 0 :(得分:0)
使用ANY SQL命令,如下所示:
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"ANY Pets.Name == %@", searchText];