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:&#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>
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:&#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>
原文:https://stackoverflow.com/questions/3321908
最满意答案
已知且相对较少的列 :如果您知道列数,比如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
fromread.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
withawk
(orpipe
withcut
for that matter) to filter the file first with the columns you require and then load it usingread.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
frombase
as:df <- df[!duplicated(df), ]
相关问答
更多-
您可以使用表达式索引执行此操作: create unique index unq_test_a_b on (test(least(a, b), greatest(a, b)); 我不认为unique约束允许表达式(并且现在没有方便的Postgres进行测试),但这基本上是相同的。 You can do this using an index on expressions: create unique index unq_test_a_b on (test(least(a, b), greatest(a, ...
-
另一个选择是 (1:nrow(gsu) %in% which(gsu=='Yes', arr.ind=TRUE)[,1])+0L #[1] 0 1 1 1 0 1 要么 apply(gsu=='Yes' & !is.na(gsu), 1, any) + 0L # 42 61 230 235 302 336 # 0 1 1 1 0 1 要么 Reduce(`|`,as.data.frame(gsu=='Yes' & !is.na(gsu))) + 0L #[1] ...
-
使用MARGIN=2 unique函数,它将返回一个删除了重复列的矩阵,默认情况下, unique删除重复的行: unique(six, MARGIN = 2) # [,1] [,2] [,3] [,4] [,5] [,6] #[1,] 2 1 1 1 1 1 #[2,] 2 2 3 1 1 1 #[3,] 1 1 1 1 2 3 #[4,] 1 2 1 3 2 ...
-
要按您的第二个数据帧进行子集化,然后计算行数: z=df1[df1$ID %in% df2$Id,] count=nrow(z) To subset your first dataframe by your second, then count the number of rows: z=df1[df1$ID %in% df2$Id,] count=nrow(z)
-
对于像这样的小桌子,这里有一种比时间更好的方法: FLUSH STATUS; SELECT SQL_NO_CACHE ...; SHOW SESSION STATUS LIKE 'Handler%'; 总结数字列是一个非常好的指标,用于比较SELECT一个变体与另一个变体。 两个EXPLAINs都说它们是Using index - 实际上在形成索引的BTree中执行查询。 没有表扫描。 请提供SHOW CREATE TABLE ,它比DESCRIBE更具描述性。 如果'缓存'很冷,那可以解释为0.07 s ...
-
R扫描两列并保持唯一(R scan two columns and keep unique)[2023-11-06]
已知且相对较少的列 :如果您知道列数,比如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", " ... -
基于具有重复行的两列R数据帧计算唯一值(Counting unique values based on two columns with repeated rows, R data frame)[2023-01-17]
您可以使用rle进行运行,并使用table进行制表: table(rle(df$column2)$values) # A B # 2 1 有关详细信息,请参阅文件和?table 。 或者,如果你想利用column1 (它来自column2 ): table(unique(df)$column2) You can use rle for runs and table for tabulation: table(rle(df$column2)$values) # A B # 2 1 See ? ... -
R中的python替代扫描('file',what = list(...))(python alternative to scan('file', what=list(…)) in R)[2024-03-01]
你可以跳过前5个,然后拿4个小组来构建一个Python列表,然后将它放在pandas中作为开始...如果pandas提供了更好的东西,我不会感到惊讶: from itertools import islice, izip_longest with open('input') as fin: # Skip header(s) at start after5 = islice(fin, 5, None) # Take remaining data and group it into g ... -
top.xy <- unique(unlist(df[1:2,])) top.xy [1] A B D Levels: A B C D top.xy <- unique(unlist(df[1:2,])) top.xy [1] A B D Levels: A B C D
-
让我们重新创建您的数据: DF <- read.table(text = " V1 V2 4 b c 14 g h 10 d g 6 b f 2 a e 5 b e 12 e f 1 a b 3 a f 9 c h 11 d h 7 c d 8 c g 13 f g", header = TRUE, stringsAsFactors = FALSE) 将两列拆分为一个向量,并在该向量中查找唯一值: u1 <- unique(u ...