Convert encoding on Windows Phone 8.1

2019-09-07 03:01发布

问题:

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