Encoding JSON to support UTF-8 characters in an android app - android

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.

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.

Related

Characters broken in React Native with Arabic and Persian Language on Android axios (XMLHttpRequest)

Is there anyone has this problem?
With Arabic and Persian language,
I am using axios. And axios using XmlHttpRequest on react-native.
There is no problem with iphone.
But on android, The characters are broken. Not only those Arabic or Persian language but also other all JSON parsed data characters.
I am using application/json for request, response.
But I can see correct data on iphone and web.
Only on android react native.
What is the problem??
Do I have to process something on the server??
Is it because some ambiguous character ? Like RTL or some special charater code in Arabic or Persian language??
I can't find the reason....
Anyone could help me?
What we found out that when typing Arabic rn fetch blob thinks that text is invalid utf8. That is why it tries to send it as base64. So, in response you need to parse base64 text using Buffer or pako.

Displaying portuguese characters Android

I'm developing an Android app and when it was suposed to write words like "não" or "cabeça", with characters with "~" or "ç" for example, it writes "ã" or "ç". I already checked source files encoding and it is UTF-8.
Looks like UTF8 interpreted as ISO-8859-x.
In theory, you could supply the javac compiler -encoding UTF-8 on the command line but that would be the wrong solution.
Instead, move all your user-facing strings to an XML resource file. In there unicode character encoding works out of the box.
Further reading: http://developer.android.com/guide/topics/resources/string-resource.html

How to use UTF-8 encoding in Android?

I am working on an French Android App, where the Accents like é, ê, â, etc.... are displaying like Symbols, which is fetched for an XML Link. How do I fix this to display the Characters in French assents?
Read UTF-8 XML file in Java – (SAX Parser)
http://www.mkyong.com/java/how-to-read-utf-8-xml-file-in-java-sax-parser/
Post UTF-8 encoded data to server loses certain characters

Android TextView encoding

After creating a database, i'm using a listview do display some lines of it. I'm facing a encoding problem trying to display a 'Ç' or 'ç' and many other characters. What is the correct approach to solve the problem?
Regards
I'd recommend to convert all the text you have to UTF-8. Android's default charset is UTF-8 and you can configure your tools (eclipse, operating system default encoding, etc.) to always use UTF-8 - this way any text you will be entering or copying into files will be UTF-8 and your worries are much less.
If you have some other external data sources like files or HTML pages, you should convert them to UTF-8 first. There are number of tools you can use - various text editors for Windows/OSX (Notepad++ my favourite), iconv unix command line tool etc. to convert between various encodings.
UTF-8 is also used by JSON which is most commonly used format for mobiles for data exchange.
You have to check defaultCharset vs your desired charset.
and you have the Charset utility at your disposal.

Does the android support Unicode natively?

Does the android support Unicode natively?
But in String.xml we have to edit it with UTF-8 ??
Any way to check the string's encoding? unicode or utf-8 ?....
Android does support Unicode.
Since you seem to be confused about the relationship between UTF-8 and Unicode, I recommend that you save yourself a lot of pain and just read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets.
If you mean UTF-16 or UTF-8 - Android works with UTF-8
Android supports Unicode characters in UTF-8 encoding - but lacks proper fonts and a complex text rendering system do display many scripts and languages properly.

Categories

Resources