我正在解析http://toutankharton.com/ws/localisations.php?l=75中的日期
如您所见,它是编码的(<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,
};
}难道new StreamReader(stream, Encoding.UTF8)还不够吗?
发布于 2011-01-13 01:43:50
如果使用UTF8字节并使用不兼容的编码(如ISO8859-1 )输出它们,就会发生这种情况。你知道真正的角色是什么吗?回过头来看,使用ISO8859-1得到一个字节数组,使用UTF8读取它,得到"è“。
var input = "è";
var bytes = Encoding.GetEncoding("ISO8859-1").GetBytes(input);
var realString = Encoding.UTF8.GetString(bytes);https://stackoverflow.com/questions/4671984
复制相似问题