2012-09-10 35 views
1

我有一個使用WebView並使用WebView.LoadData()呈現html數據的Activity; 它對大部分html數據都正常工作,但是如果Html包含像「
&#6 0; p &#6 2; &#6 0; WebView無法正確解碼該html,並在WebView中顯示html標籤。如何在WebView中解碼HTML引號

Althogh我曾經嘗試這樣的代碼:

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; 
     } 
    } 

,但於事無補。

+0

在'WebView.loadData'你傳遞任何編碼? –

+0

是的,它是utf-8 –

回答

0

嘗試使用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");