当前位置:  开发笔记 > 编程语言 > 正文

UIWebView和编码的HTML字符串?

如何解决《UIWebView和编码的HTML字符串?》经验,为你挑选了1个好方法。

我正在开发一个iPhone项目.我从RSS提要中获取HTML片段,并尝试使用loadHTMLString方法将其加载到UIWebView中.

我从Feed收到的字符串是HTML编码的.当我将其传递给webview时,它会显示已解码的HTML,这意味着它会显示标记以及页面内容.

Objective-C中是否有一种方法在将HTML传递给UIWebView之前对其进行解码?

编辑:添加编码HTML的示例:

这是一个很长的段落,但这里有一个片段:

<li>Wireless Data: Wi-Fi (802.11b/g), Nike + iPod support built in,  Maps location-based service, Bluetooth 2.1 + EDR</li>
    <li>Audio Frequency Response:&#160;20Hz to 20,000Hz</li>
    <li>Audio Formats Supported: <span>AAC </span>(16 to 320 Kbps), Protected <span>AAC  </span>(from iTunes Store), <span>MP3 </span>(16 to 320 Kbps), <span>MP3  VBR</span>, Audible (formats 2, 3, and 4), Apple Lossless, <span>WAV</span>,  and <span>AIFF</span></li>
    <li>Photo Support: Syncs iPod-viewable photos in <span>JPEG</span>,  BMP, <span>GIF</span>, TIFF, <span>PSD </span>(Mac only), and <span>PNG</span>  formats</li>
    <li>TV Out Support: 480p and 576p</li>
    <li>Video Support: H.264 video, up to 1.5 Mbps, 640 by 480 pixels, 30  frames per second, Low-Complexity version of the H.264 Baseline Profile  with <span>AAC</span>-LC audio up to 160 Kbps, 48kHz, stereo audio in  .m4v, .mp4, and .mov file formats; H.264 video, up to 2.5 Mbps, 640 by  480 pixels, 30 frames per second, Baseline Profile up to Level 3.0 with <span>AAC</span>-LC  audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file  formats; <span>MPEG</span>-4 video, up to 2.5 Mbps, 640 by 480 pixels,  30 frames per second, Simple Profile with <span>AAC</span>-LC audio up  to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats</li>
    <li>Environmental Requirements: Operating temperature: 32° to 95° F  (0° to 35° C); Nonoperating temperature: -4° to 113° F (-20° to 45° C), Relative  humidity: 5% to 95% noncondensing</li>

Dave DeLong.. 5

与@ Don的答案类似,但还有一些优化:

NSMutableString * html = [NSMutableString stringWithString:originalHTML];
NSDictionary * replacements = [NSDictionary dictionaryWithObjectsAndKeys:
                               @"<", @"<",
                               @">", @">",
                               ....,
                               nil];
for (NSString * htmlEntity in replacements) {
  [html replaceOccurrencesOfString:htmlEntity withString:[replacements objectForKey:htmlEntity] options:0 range:NSMakeRange(0, [html length])];
}

其他一些想法:将原始html加载到webview中,然后使用一些javascript来提取渲染文本,然后将渲染文本作为源管道传回webview.这可能效率不高,但可能会有效.

还有一些其他选项可以通过谷歌搜索"可可解码html实体"找到.



1> Dave DeLong..:

与@ Don的答案类似,但还有一些优化:

NSMutableString * html = [NSMutableString stringWithString:originalHTML];
NSDictionary * replacements = [NSDictionary dictionaryWithObjectsAndKeys:
                               @"<", @"<",
                               @">", @">",
                               ....,
                               nil];
for (NSString * htmlEntity in replacements) {
  [html replaceOccurrencesOfString:htmlEntity withString:[replacements objectForKey:htmlEntity] options:0 range:NSMakeRange(0, [html length])];
}

其他一些想法:将原始html加载到webview中,然后使用一些javascript来提取渲染文本,然后将渲染文本作为源管道传回webview.这可能效率不高,但可能会有效.

还有一些其他选项可以通过谷歌搜索"可可解码html实体"找到.

推荐阅读
喜生-Da
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有