Ken
Ken

Reputation: 31161

Android, Japanese and JSON

I'm writing an Android app in which I request and receive a JSON object with keys for values in Japanese. I'm converting the values I want to a string as follows:

String myString = new String(myJSONObject.getString("key").getBytes("UTF8"), "UTF8");

However when I display this it appears as nonsense like:

enter image description here

The keys and values are present and correct.

Why is this?

Upvotes: 2

Views: 1290

Answers (3)

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52936

Do you get the correct characters when you get the same JSON string with your browser? What is the content encoding of the HTTP request? Are they correct when you output them to the log? You have to figure out if it is a transfer problem, encoding mismatch problem, or just a display problem first. Try answering the questions above to narrow it down.

Upvotes: 2

Mike Sickler
Mike Sickler

Reputation: 34441

Try "UTF-8" instead of "UTF8"

Upvotes: 0

user888750
user888750

Reputation:

If it's not displaying Japanese correctly, then it's because Java is in default font mode, you'll need to update the Java fontconfig.properties file, this needs to be placed in the lib dir of your runtime. I'm not sure if this all applies for Android, as I've not made an app, but it's what I've done for regular Java development.

Also, check this out, it's for German, but UTF-8 still: decode string encoded in utf-8 format in android

Upvotes: 1

Related Questions