首页 \ 问答 \ UIWebView和一个编码的HTML字符串?(UIWebView and an Encoded HTML String?)

UIWebView和一个编码的HTML字符串?(UIWebView and an Encoded HTML String?)

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

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

在将Objective-C传递给UIWebView之前,有什么方法可以解码HTML?

编辑:添加编码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: 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>

I'm working on an iPhone project. I am getting an HTML fragment from an RSS feed and am attempting to load it into a UIWebView using the loadHTMLString method.

The string I am receiving from the feed is HTML encoded. When I pass it to the webview, it displays the decoded HTML, meaning it shows the tags along with the content of the page.

Is there a way in Objective-C to decode the HTML prior to passing it to the UIWebView?

EDIT: Adding an example of the encoded HTML:

It's a really long passage, but here's a snippet:

<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: 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>

原文:https://stackoverflow.com/questions/3321908
更新时间:2023-10-12 06:10

最满意答案

已知且相对较少的列 :如果您知道列数,比如5列,并且您想要前两列(或者只有几列),那么可以使用read.table colClasses来完成:

# header here is set to false because I don't see one in your file
df <- read.table("~/file.txt", header = FALSE, 
              colClasses=c("character", "numeric", "NULL", "NULL", "NULL"))

在这里,我们将第3列设置为第5列为NULL以便跳过它们。

未知的列/很多列:如果您不知道列或者有太多的另一种选择是使用带有awk pipe (或者带有cut pipe )来首先使用您需要的列过滤文件,然后加载它使用read.table

# header here is set to false because I don't see one in your file
df <- read.table(pipe("awk '{print $1\"\t\"$2}' ~/file.txt"), 
                       header = FALSE, sep = "\t")

删除重复的行 :使用从base duplicated

df <- df[!duplicated(df), ]

Known and relatively few columns: If you know the number of columns, say, 5 columns and you want the first two columns (or there are only few columns) then, this can be done using colClasses from read.table:

# header here is set to false because I don't see one in your file
df <- read.table("~/file.txt", header = FALSE, 
              colClasses=c("character", "numeric", "NULL", "NULL", "NULL"))

Here, we set the 3rd to 5th column to NULL so that they are skipped.

Unknown columns/Lot of columns: Another alternative if you don't know the columns or there are too many is to use pipe with awk (or pipe with cut for that matter) to filter the file first with the columns you require and then load it using read.table:

# header here is set to false because I don't see one in your file
df <- read.table(pipe("awk '{print $1\"\t\"$2}' ~/file.txt"), 
                       header = FALSE, sep = "\t")

Remove duplicated rows: Use duplicated from base as:

df <- df[!duplicated(df), ]

相关问答

更多

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)