AFNetworking返回NSCFData; registerHTTPOperationClass的问题 [英] AFNetworking returning NSCFData; issue with registerHTTPOperationClass

查看:68
本文介绍了AFNetworking返回NSCFData; registerHTTPOperationClass的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AFNetworking的新手,正在调用一个简单的登录api,该API返回json,例如:

I am new to AFNetworking and am making a call to a simple login api that returns json like:

{"status":"success","data":{"auth_token":"12jt34"}}

I正在通过以下方式进行操作,但它返回的是__NSCFData而不是我可以操纵的内容。

I'm doing it via the following but it is returning __NSCFData rather than something that I can manipuate.

NSURL *baseURL = [NSURL URLWithString:@"http://localhost:3000/arc/v1/api/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient defaultValueForHeader:@"Accept"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        uname,@"email", pwd, @"password",
                        nil];
[httpClient postPath:@"login-mobile" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSString *className = NSStringFromClass([responseObject class]);
    NSLog(@"val: %@",className);
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error retrieving data: %@", error);
}];

并输出:

2013-03-21 14:52:51.290 FbTabbed[21505:11303] val: __NSCFData

但是我希望它成为一本我可以操作的字典,我认为它应该如何工作?我在做什么错?

but I'd like it for it to be a dictionary that I can manipulate which is how I think it is supposed to work? What am I doing wrong?

推荐答案

[httpClient defaultValueForHeader:@"Accept"];

应为:

[httpClient setDefaultHeader:@"Accept" value:@"application/json"];

这篇关于AFNetworking返回NSCFData; registerHTTPOperationClass的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆