【问题标题】:How To decode HTML Quotes in WebView如何在 WebView 中解码 HTML 引号
【发布时间】:2012-09-10 13:34:50
【问题描述】:

我有一个使用 WebView 并使用 WebView.LoadData() 呈现 html 数据的 Activity; 它适用于大多数 html 数据,但如果 Html 包含像 "
& # 6 0 ; p & # 6 2 ; 0;" WebView 无法正确解码该 html 并在 WebView 中显示 html 标签。

虽然我已经尝试过这段代码:

    for(char c: rssFeed.getDescription().toCharArray()){

        switch (c) {
         case '#':  htmlBuffer.append("%23"); break;
         case '%':  htmlBuffer.append("%25"); break;
         case '\'': htmlBuffer.append("%27"); break;
         case '?':  htmlBuffer.append("%3f"); break;     
         case '&':  htmlBuffer.append("%26"); break;
         case ':':  htmlBuffer.append("%3A"); break;
         case ';':  htmlBuffer.append("%3B")  ;break;
         case '/': htmlBuffer.append("%2F"); break;


         default:
           htmlBuffer.append(c);
           break;
        }
    }

但没有帮助。

【问题讨论】:

  • WebView.loadData 中是否传递了任何编码?

标签: android html android-webview


【解决方案1】:

尝试使用 Base64 对所有内容进行编码。以下应该有效:

String content  = "html content";  // the html data
String base64 = android.util.Base64.encodeToString(data.getBytes("UTF-8"), android.util.Base64.DEFAULT);
webView.loadData(base64, "text/html; charset=utf-8", "base64");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多