1

How to get JSON response? If PHP print some JSON whole request failed, if PHP does not print anything then response succeed. How to work with AFHTTPRequestOperation ?

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        NSDictionary *parameters = @{@"foo":@"barr"};
        UIImage *image = myImage.image;
        [manager POST:@"http://local/index.php"
           parameters:parameters
    constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
        [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 0.7)
                                    name:@"file"
                                fileName:@"photo.jpg"
                                mimeType:@"image/jpeg"];
    }
              success:^(AFHTTPRequestOperation *operation, id responseObject){
                  NSLog(@"Success: %@", responseObject);
              }
              failure:^(AFHTTPRequestOperation *operation, NSError *error){
                  NSLog(@"Error %@", operation.responseString);
              }];
atako katukas
  • 21
  • 1
  • 8

1 Answers1

0

in the success block try:

NSError *e;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:[operation.responseString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&e];
Brams
  • 584
  • 4
  • 9