如何获得JSON响应?如果PHP打印一些JSON整个请求失败,如果PHP没有打印任何内容,则响应成功。如何使用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);
}];
答案 0 :(得分:0)
在成功区块尝试:
NSError *e;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:[operation.responseString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&e];