当前位置:编程学习 > C#/ASP.NET >>

关于xml中编码格式的问题

用C#写一个查询手机号码归属地的小应用,调用第三方API
得到一xml文件如下:
  <?xml version="1.0" encoding="gbk" ?> 
- <smartresult>
- <product type="mobile">
  <phonenum>152****7862</phonenum> 
  <location>山东 济南</location> 
  </product>
  </smartresult>
在VS中的代码如下:
 void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XDocument xdoc = XDocument.Parse(e.Result);
            //获取归属地信息
            string phoneLocation = xdoc.Element("smartresult").Element("product").Element("location").Value;
          
            this.txtShow.Text = string.Format("归属地:{0}", phoneLocation);
        }
问题出现了:获取归属地phoneLocation却得到了一串乱码 ,请教如何修改xml的编码格式 让归属地显示为汉字呢???          
谢谢各位!
--------------------编程问答-------------------- string phoneLocation = xdoc.Descendants("product").Select(x=>x.Element("location").Value).FirstOrDefault();
                     --------------------编程问答-------------------- 还是得到这样 "ɽ�� ����" 一串乱码 我怀疑是编码格式不对 问题是怎么转呢 我就郁闷了 .... 谢谢回复
补充:.NET技术 ,  LINQ
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,