【问题标题】:How to Decode HTML Entities (“
” and " £") from string in xcode如何解码 HTML 实体(“ ”和“£”)来自xcode中的字符串
【发布时间】:2013-09-04 03:15:37
【问题描述】:

在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 中显示的原始刺痛?任何建议...

【问题讨论】:

  • 它在你的标题中说你不能使用 NSUTF8StringEncoding... 为什么?最好使用 UTF8 或更少,Unicode 将是解决方案,因为 ASCII 不包含欧元字符....
  • 使用 Google Toolbox for Mac GTMNSString+HTML.h ,GTMNSString+HTML.m 和 GTMDefines.h 找到解决方案,首先 #import "GTMNSString+HTML.h" 像这样使用:Content_SpecialStr = [Content_SpecialStr gtm_stringByUnescapingFromHTML ];
  • 如果这是解决方案,您可以将其作为答案发布,即使它是您自己的答案:)

标签: ios xml tbxml


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    第一#import "GTMNSString+HTML.h"

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 2020-04-15
      • 2016-06-18
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多