【发布时间】:2015-03-27 19:44:57
【问题描述】:
所以我试图在线访问一个 json 文件,当我使用 AFHTTPRequestOperation 方法运行完成块时,我可以获取 JSON 文件的内容。但是当我尝试在完成块之外进行 NSLog 时,它变为空。我想知道为什么会发生这种情况以及我将如何解决这个问题。以下是我到目前为止的代码:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCredential:credentials];
[operation setResponseSerializer:[AFJSONResponseSerializer alloc]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success %@", responseObject);
jsonOutputData = [NSMutableArray arrayWithObject:responseObject];
self.newsFeedArray = [NSMutableArray arrayWithArray:[jsonOutputData copy]];
}failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"Failure: %@", error);
}];
[manager.operationQueue addOperation:operation];
NSLog(@"%@", self.newsFeedArray);
带有 Success 的 NSLog 显示 JSON,但带有 self.newsFeedArray 的 NSLog 显示 (null)。我只是想知道为什么会这样。如果您需要更多说明,请告诉我。任何帮助,将不胜感激!
谢谢!
【问题讨论】:
标签: ios objective-c json xcode afnetworking-2