我正在向服务器发出请求,服务器返回一个JSON。AFNetworking框架返回格式错误的JSON。
这是服务器发送的内容:
{"email":"XXXXXXX","firstName":"XXXXXX","lastName":"XXXXXXX","gender":"male","userToken":"XXXXXXXXXXX"}这是AFNetworking收到的内容:
{
email = "XXXXXXX";
firstName = XXXXXX;
gender = male;
lastName = XXXXXXX;
token = XXXXXXXXXXXX;
}我的代码:
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:server_ip]];
NSURLRequest *request = [client requestWithMethod:@"POST" path:path parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"%@", JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
[operation start];发布于 2012-12-25 02:33:09
打印输出的对象是从服务器接收到的JSON的NSDictionary表示。
如果您想要查看从服务器返回的原始JSON,您应该查看操作的responseString:
NSLog(@"%@", operation.responseString); https://stackoverflow.com/questions/14024493
复制相似问题