0

Suppose \u4404 means 'A' in Japanese. Following code will print 'A' on screen.

String str = "\u4404";
System.out.println(str);

This is true because encode("\u4404", unicode)='A'.

But I encountered one problem. When I process a message received over http, I get following output like

{"name":"\u4404\u2424\u4022","age":"30"}

The http header shows the reply is encoded by utf-8. But why does the ouput shows like this?

Here is my guess: Suppose the stream I received from web is mystream. Then, after we encode mystream with utf-8, I get \u4404\u2424\u4022. I have to encode mystream by TWO times, and get the right 'A' in Japanes.

Am I right? If i am right, why transfer data like this? Because of JSON? Thans very much for your ansewer!

zchen
  • 109
  • 2
  • 7
  • Might be a bug on their end. – shmosel Apr 23 '17 at 06:05
  • Possible duplicate of [How to convert a string with Unicode encoding to a string of letters](http://stackoverflow.com/questions/11145681/how-to-convert-a-string-with-unicode-encoding-to-a-string-of-letters) – Ashraful Islam Apr 23 '17 at 06:07
  • "When I process a message received over http, I get following output like" - what sort of processing? It's very unclear whether you're writing the server or the client, where you're seeing that "output" etc. Please provide a *lot* more context. – Jon Skeet Apr 23 '17 at 06:12
  • When you say "A" do you mean "あ"? – Sweeper Apr 23 '17 at 07:29

0 Answers0