0

Say i have a string like that

"title": "\u041e\u0434\u0440\u0438\u043d\u044f-\u0423\u0440\u0431\u043e\u0432\u0430 ...

What would be the best way of getting it back to normal?

I tried

byte[] b = stringBuilder.toString().getBytes();
String jstring = new String(b,"UTF-8");

yet no luck, it stays the same.

Thanks.

Roger Travis
  • 8,402
  • 18
  • 67
  • 94

5 Answers5

11

Those are Unicode escape sequences. The quickest way to decode them (non-programmatically) is simply by pasting them into your browser's console, in quotes:

"\u041e\u0434\u0440\u0438\u043d\u044f-\u0423\u0440\u0431\u043e\u0432\u0430"
> "Одриня-Урбова"

There are a few answers here that show how to decode them in Java, for example:

Community
  • 1
  • 1
Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
2

That's not UTF-8 encoded, that's just a normal string. In Java, the \uXXXX is a Unicode character escape that represents the actual Unicode character at the given code point.

So, your string is normal, it's not encoded.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
1

Did't try it, but here you may find a helpful unicode escape string parser.

Călin Darie
  • 5,937
  • 1
  • 18
  • 13
1

The unicode characters will appear like áéíóú or something like that when you show them on the screen. I phased a similar situation parsing data with MySQL db using php so on the php file I encode the strange characters tu UTF-8, the a string like the one you have appeared, then when I presented the data on a list view the characters appeared as they should.

Pedro Teran
  • 1,200
  • 3
  • 17
  • 43
1

It is already normal:

The following code

String str="\u041e\u0434\u0440\u0438\u043d\u044f-\u0423\u0440\u0431\u043e\u0432\u0430";    
System.out.println(str);

will print out: Одриня-Урбова

See the JLS-reference: Unicode-Escapes

Michael Konietzka
  • 5,419
  • 2
  • 28
  • 29