简体   繁体   中英

AFNetworking Request API iOS

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];

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);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM