AFNetworking 2为新手迁移

时间:2013-10-18 13:51:54

标签: iphone xcode ipad afnetworking afnetworking-2

我正在尝试使用AFNetworking第2版的第一步。

由于新版本现有的在线教程如 Ray Wenderlich的afnetworking-crash-course 不再工作了。

从AFNetworking 2迁移指南中我得到了以下代码:

https://github.com/AFNetworking/AFNetwor ...迁移-指南

NSURL *URL = [NSURL URLWithString:@"http://example.com/foo.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
initWithRequest:request];
operation.responseSerializer = [AFJSONSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@", responseObject);
} failure:nil];
[operation start];

此时我已经补充说 导入

#import "AFNetworking.h"

到.pch文件。

问题: 我总是收到错误消息,AFJSONSerializer是未声明的。

我忘记了什么步骤?

祝你好运

1 个答案:

答案 0 :(得分:5)

应该是AFJSONResponseSerializer,而不是AFJSONSerializer