从Web服务解析UTF8编码数据 [英] Parsing UTF8 encoded data from a Web Service
本文介绍了从Web服务解析UTF8编码数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是从 http://toutankharton.com/ws/localisations解析日期.PHP L = 75
正如你所看到的,它的编码(<名称>巴黎2ème< /名称>
)
As you can see, it's encoded (<name>Paris 2ème</name>
).
我的代码如下:
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
var contents = reader.ReadToEnd();
XElement cities = XElement.Parse(contents);
var t = from city in cities.Descendants("city")
select new City
{
Name = city.Element("name").Value,
Insee = city.Element("ci").Value,
Code = city.Element("code").Value,
};
}
不是新的StreamReader(流,编码。 UTF8)
是否足够?
推荐答案
这看起来像的东西,如果你把UTF8字节输出出现这种情况他们像一个ISO8859-1编码不兼容。你知道真正的性格是什么?回去,采用ISO8859-1得到一个字节数组,UTF8读它,赋予E。
That looks like something that happens if you take utf8-bytes and output them with a incompatible encoding like ISO8859-1. Do you know what the real character is? Going back, using ISO8859-1 to get a byte array, and UTF8 to read it, gives "è".
var input = "è";
var bytes = Encoding.GetEncoding("ISO8859-1").GetBytes(input);
var realString = Encoding.UTF8.GetString(bytes);
这篇关于从Web服务解析UTF8编码数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文