我有一个iOS 7应用程序正在调用Web服务,该服务返回带有编码字符的XML。起初只有少数几个,所以我只是这样替换它们:
- (NSString *)convertEncodedCharacters:(NSString *)html
{
// Handle escape characters
html = [html stringByReplacingOccurrencesOfString:@"’" withString:@"'"];
html = [html stringByReplacingOccurrencesOfString:@"‘" withString:@"‘"];
html = [html stringByReplacingOccurrencesOfString:@"—" withString:@"-"];
html = [html stringByReplacingOccurrencesOfString:@""" withString:@"\""];
html = [html stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
html = [html stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
html = [html stringByReplacingOccurrencesOfString:@">" withString:@">"];
html = [html stringByReplacingOccurrencesOfString:@"–" withString:@"–"];
html = [html stringByReplacingOccurrencesOfString:@"“" withString:@"“"];
html = [html stringByReplacingOccurrencesOfString:@"”" withString:@"”"];
html = [html stringByReplacingOccurrencesOfString:@"‚" withString:@"‚"];
html = [html stringByReplacingOccurrencesOfString:@" " withString:@" "];
return html;
}
但现在内容变得越来越复杂,我不断遇到新角色。有没有办法将所有编码的字符转换成人类可读的字符?
答案 0 :(得分:0)
从GitHub检查这个类,正是你要找的那个
https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/NSString+HTML.m