我正在尝试让 AFJSONRequestOperation 与http://www.crowdkind.org/mobile/offers一起使用。
我通过同步部分,它返回数据并将其放入表中就好了。当我将其转换为 AFJSONRequestOperation 时 - 我没有得到响应。该操作是按照 NSLog 告诉我的那样发送的。但我从来没有得到“操作成功或失败”。知道会发生什么吗?这是我的 searchBarButtonClicked 方法...
URLtoSearch 设置为... http://www.crowdkind.org/mobile/offers。(请随意点击,因为它是有效的 JSON)。
- (void)searchBarSearchButtonClicked
{
searchResults = [NSMutableArray arrayWithCapacity:10];
[queue cancelAllOperations];
isLoading = YES;
[self.tableView reloadData];
NSURL *url = [self urlWithSearchText:URLtoSearch];
NSLog(@"URL: %@", URLtoSearch);
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Operation succeeded");
[self parseDictionary:JSON];
[searchResults sortUsingSelector:@selector(compareName:)];
isLoading = NO;
[self.tableView reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Operation failed");
[self showNetworkError];
isLoading = NO;
[self.tableView reloadData];
}];
operation.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
[queue addOperation:operation];
NSLog(@"Operation added");
}
我没有得到回应。检查链接,它是有效的 json。任何想法都非常感谢!