Dex*_*url 0 nsdictionary nspredicate ios
我正在尝试过滤来自Facebook API的响应,JSON看起来像这样:
{
"Data": [
{
"first_name" : "Joe",
"last_name" : "bloggs",
"uuid" : "123"
},
{
"first_name" : "johnny",
"last_name" : "appleseed",
"uuid" : "321"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我将它加载到NSDictionary中,像访问它一样 [[friendDictionary objectForKey:@"data"] allObjects]
我现在正在尝试根据first_name并last_name根据有人在文本字段中输入名称进行过滤.这是我所拥有的,但它的失败可怕:
NSPredicate *filter = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"ANY.first_name beginswith[c] %@ OR ANY.last_name beginswith[c] %@", friendField.text, friendField.text]];
NSLog(@"%@", [[[friendDictionary objectForKey:@"data"] allObjects] filteredArrayUsingPredicate:filter]);
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助,谢谢你们
你觉得太复杂了.
stringWithFormat在predicateWithFormat这里毫无意义.[friendDictionary objectForKey:@"Data"]返回一个数组,allObjects这里错了.这给了
NSPredicate *filter = [NSPredicate predicateWithFormat:@"first_name beginswith[c] %@ OR last_name beginswith[c] %@",
friendField.text, friendField.text];
NSArray *filteredArray = [[friendDictionary objectForKey:@"Data"] filteredArrayUsingPredicate:filter];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4268 次 |
| 最近记录: |