以下是我的回复格式:
[
{
"id": 9001,
"name": "A to B",
"description": "A to B via mooncity",
"sequence":[
1001,
1002,
1003
]
},
{
"id": 9002,
"name": "B to D",
"description": "B to D via suncity",
"sequence":[
1010,
1002,
1009
]
}
]
现在,我希望将1002
中包含sequence array
的所有词典添加到另一个数组中。
我累了
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"%K contains[c] %@", @"sequence", @"1002"];
但是上面的谓词适用于字典数组。虽然在这种情况下无效。
非常感谢任何帮助。
答案 0 :(得分:1)
在swift中它对我有用
let array = ["101","110","133"]
let dict = ["sequence":array,"id": "10"] as [String : AnyObject]
let array1 = ["100","110","133"]
let dict1 = ["sequence":array1,"id": "10"] as [String : AnyObject]
let fArray : NSArray = [dict,dict1] as NSArray
let pred = NSPredicate(format: "ANY self.sequence contains[c] %@", "100")
let test = fArray.filteredArrayUsingPredicate(pred)
print(test)
out put
[{
id = 10;
sequence = (
100,
110,
133
);
}]
答案 1 :(得分:1)
NSPredicate *pred = [NSPredicate predicateWithFormat:@"CAST(sequence, 'NSString') contains[cd] %@", @"1002"];
NSArray *result = [your_array filteredArrayUsingPredicate:pred];