从AFNetworking 2.4.1获得明确的回应

时间:2014-09-24 10:32:37

标签: objective-c xcode post afnetworking afnetworking-2

我正在发送POST请求:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSDictionary *parameters = @{@"method": @"login", @"email":@"email", @"password":@"password"};
[manager POST:@"http://www.apiwebsite.com" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

我的responseObject是:

  

JSON:< 0d0a7b22 72657370 6f6e7365 223a224f 4b222c22 30223a22 6d61696c   696e675f 6b657922 2c223122 3a226239 65653766 34643238 64333730   30666663 37393734 65376665 66626663 3136227d>

但是用POSTMAN调用api我得到:

  

{“response”:“OK”,“id”:“1234223123”}

如何使用普通或JSON响应来使用它? 谢谢!

1 个答案:

答案 0 :(得分:0)

要使JSON对象使用正确的序列化程序AFJSONResponseSerializer而不是您现在使用的AFHTTPResponseSerializer

出于调试目的,将NSData转换为NSString      NSLog(@" JSON:%@",[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);