2

我正在向服务器发出请求,服务器返回一个 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];
4

1 回答 1

4

您要打印的对象是从服务器接收到的 JSON 的 NSDictionary 表示。

如果要查看从服务器返回的原始 JSON,则应查看操作的 responseString:

NSLog(@"%@", operation.responseString);  
于 2012-12-24T18:33:09.407 回答