2
votes

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.

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
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.
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
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.
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

1 Answers

1
votes

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.