views:

73

answers:

2

Help me please. I have problem with encoding response string after GET request:

var m_refWebClient = new WebClient();
var m_refStream = m_refWebClient.OpenRead(this.m_refUri);
var m_refStreamReader = new StreamReader(this.m_refStream, Encoding.UTF8);
var m_refResponse = m_refStreamReader.ReadToEnd();

After calling this code my string m_refResponse is json source with substrings like \u041c\u043e\u0439. What is it? How to encode it for Cyrillic? I am very tired after a lot of attempts.

corrected

+2  A: 

I'm not 100% on this, but I would assume you'd have to pass Encoding.Unicode to StreamReader.

Zor
`Encoding.Unicode` is actually the UTF-16LE encoding. (Microsoft love to describe UTF-16LE as ‘Unicode’, as that's the encoding Windows uses for string storage internally, but the naming is highly misleading.) It's *extremely* unusual for a web server to return UTF-16-encoded content (being non-ASCII-compatible, it tends to break a lot if they try); UTF-8 is a much more likely possibility.
bobince
+2  A: 

Am I missing something here?

What is it?

"\u041c\u043e\u0439" is the String literal representation of Мой. You don't have to do anything more, Strings are Unicode, you've got your Cyrillic already.

(Unless you mean you literally have the sequence \u041c\u043e\u0439, ie. the value "\\u041c\\u043e\\u0439". That wouldn't be the result of an encoding error, that would be something happening at the server, for example it returning a JSON string, since JSON and C# use the same \u escapes. If that's what's happening use a JSON parser.)

bobince
@bobince thanks a lot!!! It was my mistake, that i did not provide full information as @Jon said! my response is json document, but before parsing it with Newton's json library, i watched it in test console)))) I forgot about formating, sorry! now it works nice!!!
Edward83