我是 AFNetworking 的新手,正在调用一个返回 json 的简单登录 api,例如:
{"status":"success","data":{"auth_token":"12jt34"}}
我正在通过以下方式进行操作,但它返回的是 __NSCFData 而不是我可以操纵的东西。
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
但我希望它成为一本我可以操纵的字典,这就是我认为它应该如何工作的方式?我究竟做错了什么?