问题
Arabic data is showing ????? characters from asp.net mvc to ios app using afnetworking library to handle the response object.
#import "AppGateway.h"
//the web location of the service
#define kAPIHost @"domain"
#define kAPIPath @"Home/GetNews/"
@implementation AppGateway
/*Singleton*/
+(AppGateway*)sharedInstance
{
static AppGateway *sharedInstance = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
sharedInstance = [[self alloc] initWithBaseURL:[NSURL URLWithString:kAPIHost]];
});
return sharedInstance;
}
-(AppGateway*)init{
self = [super init];
if(self!=nil) {
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self setDefaultHeader:@"Accept" value:@"application/json"];
}
return self;
}
-(void)commandWithParams:(NSMutableDictionary *)params onCompletion:(JSONResponseBlock)completionBlock{
NSMutableURLRequest *apiRequest = [self multipartFormRequestWithMethod:@"POST"
path:kAPIPath
parameters:params
constructingBodyWithBlock:^(id <AFMultipartFormData>formData){
}];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:apiRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"AFNTSUCCESS");
//This is where response object carry arabic data corrupted to '??????????'
completionBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"AFNTFAILURE");
completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
}];
[operation start];
}
@end
This is my class i'm using in order to connect to the mvc actions. Thank you
回答1:
yes it worked it is not from the afnetworking or mvc the problem was with in the server. sorry for that
来源:https://stackoverflow.com/questions/16162494/arabic-data-is-showing-characters-from-asp-net-mvc-to-ios-app-using-afnetw