iphone - ASIHttpRequest 响应的编码问题

标签 iphone xml utf-8 asihttprequest basecamp

伙计们,我已经尝试了所有但没有成功。

创建:

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:self.urlString]]; 
request.delegate = self;
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setRequestMethod:@"PUT"];
[request addRequestHeader:@"Accept" value:@"application/xml"];
[request addRequestHeader:@"Content-Type" value:@"application/xml; charset=UTF-8;"];

显示:

- (void)requestFinished:(ASIHTTPRequest *)request
{
        [self HideProgressing];

//      NSString *poweredBy = [[request responseHeaders] objectForKey:@"X-Powered-By"];
//      NSString *contentType = [[request responseHeaders] objectForKey:@"Content-Type"];

        NSString *body = [request responseString];
        //NSString *body = [[NSString alloc] initWithData:[request responseData] encoding:NSUTF8StringEncoding];
        NSLog(@"%@\n%@", body, request.responseStatusMessage);

甚至“内容类型”也说它有 UTF-8。但我只看到像“ዹ”这样的东西而不是西里尔符号。

有人用编码解决了同样的问题吗?

如果有帮助,数据来自 Basecamp API。谢谢。

alt text

最佳答案

这是一个 HTML 编码/解码问题。请注意,URL 编码/解码是不同的。

西里尔字母的编码/解码表 - http://webdesign.about.com/od/localization/l/blhtmlcodes-ru.htm

代码方法: http://code.google.com/p/statz/source/browse/trunk/NSString%2BHTML.h http://code.google.com/p/statz/source/browse/trunk/NSString%2BHTML.m

或者这个:https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/GTMNSString%2BHTML.m

我还没有实现,现在有其他任务。

祝你好运。

关于iphone - ASIHttpRequest 响应的编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4131210/

相关文章:

iphone - 如何使用objective-c从Twitter获取用户帐户信息?

iphone - NSLocalizedString显示键值

c# - 用 C# 编写 XML

xml - Android:使用 ISO-8859-1 编码的 SaxParser 问题

PHP、mysql编码UTF-8

c++ - 从 C++ 文件中读取 Unicode 字符

iphone - 使用AVPlayer播放时如何静音

iphone - 在 Collection View 中加载图像的更快方法

c# - 对 XElement 进行空检查

mysql - 为什么mysql服务器字符不能设置为my-default.ini(windows)中的设置(utf8)?