Convert encoding on Windows Phone 8.1

♀尐吖头ヾ 提交于 2019-12-12 04:53:07

问题


I'm trying to download content from website in Windows Phone 8.1 app and I have a problem with encoding.

I know there is just UTF-8 and UTF-16 so I'm trying to use the generated class from here for conversion: http://www.hardcodet.net/2010/03/silverlight-text-encoding-class-generato

(With settings - Encoding name ornumeric code page: windows-1250)

Than I'm trying to use it this way:

private string Encode(string xml)
{
    Encoding win1250 = new Windows1250Encoding();
    Encoding utf = Encoding.UTF8;
    byte[] win1250Bytes = win1250.GetBytes(xml);
    byte[] utfBytes = Encoding.Convert(win1250, utf, win1250Bytes);
    return XDocument.Parse(utf.GetString(utfBytes, 0, utfBytes.Length));
}

But I get an error:

The encoding [�] cannot decode byte value [{1}]. Set the FallbackCharacter property in order to suppress this exception and decode the value as a default character instead.

What is wrong?

Thanks

来源:https://stackoverflow.com/questions/26484076/convert-encoding-on-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!