阿拉伯数据显示??????从 asp.net mvc 到 ios app 的字符使用 afnetworking 库来处理响应对象。
#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
这是我用来连接到 mvc 操作的课程。谢谢