AFNetworking变音符号

时间:2013-02-22 19:49:06

标签: encoding afnetworking

我正在使用AFNetworking与我的JSON API进行通信。除了向德国变音符号(即äöüß)发送请求外,一切都很好。

我正在使用共享实例

+(LFMessaging*)shared
{
    static LFMessaging *sharedInstance = nil;
    static dispatch_once_t oncePredicate;
    dispatch_once(&oncePredicate, ^{
        sharedInstance = [[self alloc] init];
    });    
    return sharedInstance;
}

发送数据我使用此方法使用AFHTTPClient的子类:

[parameters setValue:cmd forKey:@"cmd"];
NSMutableURLRequest *apiRequest =
[self multipartFormRequestWithMethod:@"POST"
                                path:[NSString stringWithFormat:@"http://%@%@", _domain, _target]
                          parameters:(NSDictionary*)parameters
           constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
               //TODO: attach file if needed
           }];

AFJSONRequestOperation* operation = [[AFJSONRequestOperation alloc] initWithRequest: apiRequest];
operation.JSONReadingOptions = NSJSONReadingMutableContainers;

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
...

当具有德国变音符号的参数通过api时,似乎打破了。服务器没有收到正确的字符串。

如果服务器在json结果中发送变音符号,一切都很好。

1 个答案:

答案 0 :(得分:0)

self.stringEncoding = NSUTF8StringEncoding;

解决了问题

相关问题