如何解码HTML实体(“ “和”£“)来自xcode中的字符串

时间:2013-08-31 14:10:21

标签: ios xml tbxml

xml数据中的

<content_special>
    SAT 17TH TEST test club cheap drinks £3 shots £5 bottles $beers
</content_special>

我使用此代码获取此字符串

TBXMLElement *Content_Special=[TBXML childElementNamed:@"content_special" parentElement:Club];
            NSString *Content_SpecialStr = [TBXML textForElement:Content_Special];

当我NSLog(@"Content_special:%@",Content_SpecialStr);

像这样打印

 Content_special:SAT 17TH TEST&#13;
test club&#13;
cheap drinks&#13;
&#13;
&#163;3 shots&#13;
&#163;5 bottles&#13;
&#13;
$beers

我怎样才能获得Xlm中显示的原始刺痛?任何建议......

2 个答案:

答案 0 :(得分:3)

使用Google Toolbox for Mac找到解决方案GTMNSString+HTML.hGTMNSString+HTML.mGTMDefines.h

首先#import "GTMNSString+HTML.h"

像这样使用:Content_SpecialStr = [Content_SpecialStr gtm_stringByUnescapingFromHTML];

答案 1 :(得分:0)

确保您的数据xml文件具有utf-8编码http://www.w3schools.com/xml/xml_encoding.asp