2

I'm doing a request to the server and the server returns a JSON. AFNetworking framework returns a wrong formatted JSON.

This is what the server sends:

{"email":"XXXXXXX","firstName":"XXXXXX","lastName":"XXXXXXX","gender":"male","userToken":"XXXXXXXXXXX"}

This is what AFNetworking receives:

{
email = "XXXXXXX";
firstName = XXXXXX;
gender = male;
lastName = XXXXXXX;
token = XXXXXXXXXXXX;
}

My code:

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];
1
  • Your json doesn't contain lastname and still the framework returns a json with lastname? Dec 24, 2012 at 18:20

1 Answer 1

4

The object you are printing out is the NSDictionary representation of the JSON received from the server.

If you want to see the raw JSON returned from the server, you should look at the responseString of the operation:

NSLog(@"%@", operation.responseString);  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.