1

阿拉伯数据显示??????从 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 操作的课程。谢谢

4

1 回答 1

0

是的,它起作用了,它不是来自服务器中的问题所在的 afnetworking 或 mvc。对此感到抱歉

于 2013-04-23T07:03:49.170 回答