C#在TextBlock中显示特殊字符

问题描述:

在我的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”); –

WebClient的可能是没有使用正确的编码,以下载中心您的RSS提要,尝试编码属性设置为正确的(也许Unicode的?):

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

,或者如果你知道这是用来特定的编码:

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