ResponseObject is not JSON, but NSInLineData for AFHTTPRequestOperationManager

The following code is to send images through the operation Queue. All requests are started one after another correctly, the server response contains the name of the image file that the client should have. The problem is that in reponseObject for the success / failure block, JSON parsing is not expected, but the type NSInLineData shown in the debugger. Now I suspect that the code to create the operation from NSMutableURLRequest caused a problem. Please, help.

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; NSMutableURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:podURLString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { NSError *error; BOOL success =[formData appendPartWithFileURL:imgURL name:@"images" fileName:img.path mimeType:@"image/jpg" error:nil]; if (!success) NSLog(@"appendPartWithFileURL error: %@", error);} error:nil]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Image Success: %@", [responseObject description]); NSString *imagePath = [response objectForKey:@"imageFileName"]; [self.delegate networkManager:self didSubmitDeliveryImageForImageID:imagePath]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Image Error: %@", error); NSLog(@"image error: %@", [operation.responseObject description]); NSString *imageFilePath = [operation.responseObject objectForKey:@"imageFileName"]; [self.delegate networkManager:self didFailSubmitDeliveryImageForImageID:imageFilePath]; }]; [manager.operationQueue addOperation:operation]; 
+7
ios afnetworking-2
source share
2 answers

When you get the answer as NSInLineData. Good to go now. You can write one line of code below to get NSDictionary if it supports json format.

 NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObjec options:0 error:nil]; 
+6
source

Just add this line of code before the AFHTTPRequestOperation block

 **operation.responseSerializer = [AFJSONResponseSerializer serializer];** 
+2
source

All Articles