我的 AFNetworking API 响应包含一个 json 对象“place”,它可以是“restaurant”或“store”。仅当地点对象包含关键字“存储”时,我才想过滤响应以添加到 location_results 数组
这是我的 AFNetworking 请求
[[LocationApiClient sharedInstance] getPath:@"locations.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id response) {
NSLog(@"Response: %@", response);
NSMutableArray *location_results = [NSMutableArray array];
for (id locationDictionary in response) {
Location *location = [[Location alloc] initWithDictionary:locationDictionary];
[location_results addObject:location];
}
self.location_results = location_results;
[self.tableView reloadData];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error fetching locations!");
NSLog(@"%@", error);
}];
}
我试着添加这个
for (id locationDictionary in response) {
Location *location = [[Location alloc] initWithDictionary:locationDictionary];
if([[location objectForKey:@"place"] isEqualToString:@"Store"]) // Added this line
[location_results addObject:location];
}
但我收到一个错误 - 'Location' 没有可见的@interface 声明选择器'objectForKey'
之前如何过滤此响应[location_results addObject:location];
?