iOS:处理HTTP请求的unicode字符 [英] iOS: handling HTTP request's unicode characters
本文介绍了iOS:处理HTTP请求的unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我NSLog HTTP请求响应字符串时,它显示为ãÃÂÃÂÃÂÃããÃÂÃÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂand and and and and and and我正在使用ASIHTTPRequest,如上所述这里我已将响应编码设置为NSUTF8StringEncoding(服务器使用UTF-8相同)但它没有帮助。有人可以告诉我如何在我的应用程序中支持unicode角色?谢谢。
When I NSLog HTTP requests response string, it appears as "ãÃÂïãÃâ¬ÃÂãÃÂÃâãÃÂ" and something different appears on UILabel but not the same as I expect in Japanese/Chinese format. I am using ASIHTTPRequest and as mentioned here I have set response encoding to NSUTF8StringEncoding(server uses UTF-8 same) but it didn't help. Could someone please tell me how to support unicode character in my App? Thanks.
- (void)getData
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[dataUrl stringByAppendingFormat:@"%@",self.selectedID]]];
[request setResponseEncoding:NSUTF8StringEncoding];
SBJSON *parser = [[SBJSON alloc] init];
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithCapacity:3];
[data setObject:self.username forKey:@"username"];
[data setObject:self.password forKey:@"password"];
NSString *dataJSON = [parser stringWithFragment:data error:nil];
[request appendPostData:[dataJSON dataUsingEncoding:NSUTF8StringEncoding]];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestSuccess:)];
[request setDidFailSelector:@selector(requestFailed:)];
[self.queue addOperation: request];
[self.queue go];
}
- (void)requestSuccess:(ASIHTTPRequest *)request
{
NSLog(@"success: %@", [request responseString]);
}
推荐答案
我设法解决了这个问题。以下是更改!
I managed to fix this. Following is the change!
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[dataUrl stringByAppendingFormat:@"%@",self.selectedID]]];
[request setResponseEncoding:NSUTF8StringEncoding]; -- > Wrong!!!
request.defaultResponseEncoding = NSUTF8StringEncoding; --> Correct!
这篇关于iOS:处理HTTP请求的unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文