2013-10-09 102 views
0

在我的Windows Phone應用程序中,我從Internet獲取RSS並解析XML。 我從rss中取出標題和描述,並將它們顯示在TextBlock中。C#在TextBlock中顯示特殊字符

在這裏我發現一些問題,特殊字符被菱形代替包含「?」。

 /*CONNECTION AND DOWNLOAD RSS*/ 
     WebClient wc = new WebClient(); 
     wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(load_web_news); 
     wc.DownloadStringAsync(new Uri("http://.../rssFeedNews.asp")); 
     .... 
    /*SAVE RSS*/ 
      TextBlock tbTitle = new TextBlock(); 
      Run rTitle = new Run(); 
      rTitle.Text = rss.Title; 
      Run rDescription = new Run(); 
      rDescription.Text = rss.Description; 
      tbTitle.Inlines.Add(rTitle); 
     .... 
     /*PARSING*/ 
    private void load_web_news(object sender, DownloadStringCompletedEventArgs e) 
    { 
     XElement xmlitems = XElement.Parse(e.Result); 
     List<XElement> elements = xmlitems.Descendants("item").ToList(); 
     foreach (XElement rssItem in elements) 
       { 
        RSSItem rss = new RSSItem(); 
        rss.Description1 = rssItem.Element("description").Value; 
        String title = rssItem.Element("title").Value; 

如何在Windows手機應用程序顯示例如特殊字符 「A」 「E」 「°」 等...?

+0

意大利語言精確編碼是 :wc.Encoding = System.Text.Encoding.GetEncoding( 「ISO-8859-1」); –

回答

2

WebClient的可能是沒有使用正確的編碼,以下載中心您的RSS提要,嘗試編碼屬性設置爲正確的(也許Unicode的?):

wc.Encoding = System.Text.Encoding.Unicode; 

,或者如果你知道這是用來特定的編碼:

wc.Encoding = System.Text.Encoding.GetEncoding("encoding name here") ;