2

I'm trying to display utf-8 character in a ListView in my android app, but what appears is series of question mark????? This is what the output looks like:

[{"ImageID":"1","ItemID":"Item1","ItemID_AM":"????
???","ImagePath":"http:\/\/10.0.2.2\/android\/Pagination\/pics\/pic_a.png"},{"ImageID":"2","ItemID":"Item2","ItemID_AM":"????
????","ImagePath":"http:\/\/10.0.2.2\/android\/Pagination\/pics\/pic_b.png"},...

I already used: header('content-type: application/json; charset=utf-8'); But nothing changed. Can someone help please?

Thanks.

skjcyber
  • 5,759
  • 12
  • 40
  • 60
B3738
  • 51
  • 1
  • 1
  • 10
  • 1
    Does your list view really display JSON? Or is this the JSON input you are showing in your question? Please use fiddler or a similar tool to capture the transmitted JSON data and add it to your question. And please add the code for requesting the data and parsing the JSON as well. – Codo Oct 04 '13 at 13:41
  • Could you try to show the complete JSON in your textView, your JSON might not be correct 'utf-8' encoded. If your data comes from a db try this: mysql_set_charset('utf8',$dbLink); – A.S. Oct 04 '13 at 13:44
  • I've a database and I used php to convert the results into json format, and then I want it to be displayed in my android ListView. – B3738 Oct 04 '13 at 13:49
  • So the checklist should look like this: 1.) Charset of your TEXT/VARCHAR = utf-8? 2. mysql_set_charset('utf8',$dbLink); ? 3. php-code saved as utf8 charset – A.S. Oct 04 '13 at 13:51
  • But in mysql database all the characters are displayed correctly, but when I browse it in json, well the question mark "????" appears. So the question mark also displayed in my android ListView, because that is what it gets from the json. – B3738 Oct 04 '13 at 14:15
  • What happens when you load the JSON with a browser? – Alastair McCormack Oct 07 '13 at 17:15
  • **Alastair McCormack** it displays series of question marks. As a result it, it also displays question mark in my android ListView. – B3738 Oct 08 '13 at 12:34
  • See http://stackoverflow.com/questions/19362095/displaying-unicode-characters-in-json/19382335#19382335 – Alastair McCormack Oct 15 '13 at 13:23

1 Answers1

1

Java strings use Unicode and the JSON strings are UTF-8 encoded. Most likely, you must convert the UTF-8 JSON to Unicode.

Search: java string utf8, for example How to convert Strings to and from UTF8 byte arrays in Java

The easiest way though, would be to let an appropriate JSON library do the decoding. Maybe org.json - Android or How to parse JSON in Android is of help.

Update:

Maybe everything is fine and it is just the font not capable of displaying the needed characters. If this is the case, the solution to the problem would be to install an appropriate font.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • Okay Olaf I'll check it out. – B3738 Oct 09 '13 at 14:14
  • what is the encoding of Java strings ? Every unicode has to be encoded to be able to store on memory. – Jai Pandit Aug 04 '16 at 21:03
  • See [Oracle - Class String](http://docs.oracle.com/javase/8/docs/api/java/lang/String.html) "A String represents a string in the UTF-16 format ...". There's also [Oracle - Unicode Character Representations](http://docs.oracle.com/javase/8/docs/api/java/lang/Character.html#unicode) "The char data type ... are based on the original Unicode specification, which defined characters as fixed-width 16-bit entities." Stackoverflow also has quite a few questions on the subject, http://stackoverflow.com/search?q=java+string+internal+representation – Olaf Dietsche Aug 05 '16 at 08:00