Reputation: 1704
Right now I have JSON data, and it has things in it like follows:
\u00e9
How can I change its format so that can be expressed normally as an "é"?
Upvotes: 1
Views: 2674
Reputation: 29473
org.apache.commons.lang.StringEscapeUtils.unescapeJava("\\u00e9")
Upvotes: 2
Reputation: 234795
You don't say whether you are using any JSON tools, but some of them have support for this kind of escape handling. If you're processing it yourself, there's not much you can do other than parse the escape sequence yourself. There are various ways to do it (including using regular expressions), but this is pretty simple to do directly. Just look for the "\u" prefix, take the next four characters and parse them as a hex integer. Then cast the result to a char
and use that in place of the six original characters.
Upvotes: 1
Reputation: 1870
Unicode characters in Java are considered literals. For example,
String foo = "\u00e9";
is considered a literal character é
. Having said that, does this sample program give you any ideas?
public class Foo {
public static void main(String[] args) {
String myCharacter = "\u00e9";
System.out.println(myCharacter);
}
}
Have a look at String and Character.
Upvotes: 0