如何在一个获取请求中保存一个responseObject AFNetworking到nsarray?

时间:2015-03-24 13:01:58

标签: ios objective-c afnetworking

我已经杀了几个小时,以了解如何在responseObjectAFNetworking的抓取请求中保存nsarray。无法弄清楚如何保存它,以便我可以在我的代码的另一部分中使用它。

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
 }];

1 个答案:

答案 0 :(得分:1)

__block NSArray* responseObjectArray = nil;

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

[manager GET:@"example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
    responseObjectArray = (NSArray*)responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];