0

I have been going head over heels to solve this. I have a json feed that returns UTF based data

For example:

{"statusCode":200,"body":[{"wall_id":889370,"posted_by":"nicol","poster_id":1113,"poster_image_thumbnail":"http://www.mface.me/images/avatar/thumb_f713034d70bcd5e4d68b5ed5.jpg","post_type":"profile","post_content":[{"text":"咯. .... etc

I can successfully read this into a json object, but when i display the value from "text" all i get are question marks, It's the same when i print to the console.

The same feed works for my iPhone app without any issues.

Any suggestions are highly appreciated

Edit:

I can safely say that the phone i am testing with is running Ginger bread and has no issues displaying UTF-8 characters. It must be how async http is reading the UTF characters. I am not sure how to solve this.

Veeru
  • 4,936
  • 2
  • 43
  • 61
  • It cold be that your Android device does not have the correct fonts installed to display unicode characters. http://stackoverflow.com/questions/5300391/unicode-support-for-android – Nathan Villaescusa Oct 06 '12 at 17:48
  • Hi Nathan, but this is simplified chinese. Do you think Android has issues with it? The last time i have used UTF, it was with xml and i was successful with something like this InputSource raw=new InputSource(new StringReader(response)); xr.parse(raw); //xr is a xml reader But here, am stuck with JSon and am not sure how to handle it. – Veeru Oct 06 '12 at 17:51
  • Could you post the section of code where you fetch the html and you parse the JSON? Are you using a library to do the JSON parsing? – Nathan Villaescusa Oct 06 '12 at 18:01
  • Replied with an answer Nathan, but i still could not get to display chinese in LogCat! :( – Veeru Oct 06 '12 at 18:05
  • Logcat seems to support UTF-8 http://code.google.com/p/android/issues/detail?id=1590, what happens when you try to log Chinese character that you entered yourself? – Nathan Villaescusa Oct 06 '12 at 18:08
  • I was expecting it to be so. ALl i get is question marks (mostly) – Veeru Oct 06 '12 at 18:42

1 Answers1

1

Thanks for the responses, i think i have figured it out. well, atleast that's what i think. Text seems to show properly in UTF.

For other friends who would like to know the answer, this is what i did

tmpPostContent.text=new String(postContentRecord.getString("text").getBytes("UTF-8"), "UTF-8");

I am not sure if this indeed the right solution, but seems to work. Please correct me if i am wrong.

Veeru
  • 4,936
  • 2
  • 43
  • 61