Setting TextView's text as non-English text received from JSON response

I'm getting back names of (Foursquare) venues from a server call where the names of the venues returned can be in English or non-English.

Assume the venue name is in a JSON object as follows:

{... "name":"venue name which can be in any language" ...}

I'm creating a JSONObject from this response and then pulling out the name of the venue as follows:

String name = jsonObject.getString("name");

Lastly, I'm setting the TextView's text to show the name of the venue as follows:


I'm finding however for Arabic names that where the Arabic characters are joined in the original JSON object (as they should be), the characters that show in the app (i.e. in the TextView) are disjoint. (I'm not too familiar with other languages so can't really tell if they're showing incorrectly too.)

Is there something additional I should be doing to pull out non-English names correctly from the JSON object and setting it as the text of a TextView, or is it down to the phone to decide how the text will be displayed?

Edit: I've tried parsing the server response (as suggested by @bbedward) explicitly specifying the content encoding as UTF-8 as follows...

HttpEntity httpEntity = httpResponse.getEntity(); String responseMessage = EntityUtils.toString(myHttpEntity, "UTF-8"); JSONObject jsonObject = new JSONObject(responseMessage);

... but still no joy. (Arabic characters appear, as before, disjoint in words where they should be joint up.) Could it be a phone thing or is there something extra needing to be done myself to get the words/characters to show proper in non-English languages? Perhaps the server needs to explicitly specify a "Content-Type" header with value "UTF-8"?

-------------Problems Reply------------

I'm going to answer anyway, I'm guessing you aren't getting your json in UTF-8 as i had a similar problem, I believe json won't come any other way.

Complete Example

The only things to concern yourself with this is setting the encoding for the InputStreamReader and creating the JSONObject

private DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("");
// Depending on your web service
httppost.setHeader("Content-type", "application/json");
String result = null;
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

InputStream inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"), 8);
StringBuilder sb = new StringBuilder();

String line = null;
while ((line = reader.readLine()) != null)
sb.append(line + "\n");
JSONObject myJObject = new JSONObject(sb.toString();
catch (Exception e)
try{if(inputStream != null)inputStream.close();}catch(Exception none){}

add this line when you connect to mysql:

mysql_set_charset('utf8', $con);


$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_set_charset('utf8', $con);

Category:android Views:0 Time:2012-03-13

Related post

  • Arabic & English text problem in Galaxy S and Nexus S in TextView 2011-03-24

    With a TextView with right gravity when I write a mix of English and Arabic texts, some English texts are moved to the right of the TextView and are not shown. This may be because of some sort of arabizer in Samsung. Any suggestions to fix that? ----

  • Is there an algorithm that extracts meaningful tags of english text 2008-09-15

    I would like to extract a reduced collection of "meaningful" tags (10 max) out of an english text of any size. is quite interesting but the algorithm seems very basic (just word counting) Is there any other existing algorithm to

  • Gettext: Is it a good idea for the message ID to be the english text? 2008-10-19

    We're getting ready to translate our PHP website into various languages, and the gettext support in PHP looks like the way to go. All the tutorials I see recommend using the english text as the message ID, i.e. gettext("Hi there!") But is that really

  • How to enter Text other than english and process the entered text 2009-12-12

    I have a doubt is it possible to give text other than English in my latest project I need to support Hindi ,Tamil and French so if user selects language as Hindi or Tamil or French so what ever value the user is giving in the textbox it must be displ

  • problems with sending non-english text over mail 2010-01-17

    I am trying to send non-english text over mail. The non-english text is on the "from" field of the mail (the text that appears beside the email address). In the recipient's mailbox, the non-english text is seen as a series of question marks. What cou

  • Why WPF ScrollViewer Language is tr but ContextMenu command texts are in English? 2010-01-27

    I have a ScrollViewer in WPF. when I make right click to scroll control, context menu is opening and write commands like "Scroll Here, "Scroll Top" vs. vs. although my ScrollViwer Language is "tr-Tr" , Why Scrollviewer ContextMenu command texts are i

  • How to get TimeZone.getDisplayName(locale) value to return non-English text? 2010-03-02

    The code below outputs "Japan Standard Time". TimeZone tz = TimeZone.getTimeZone("Asia/Tokyo"); Locale locale = new Locale("ja_JP"); System.out.println(tz.getDisplayName(locale)); I am expecting it to output something with Kanji along the lines of "日

  • How do I use VIM effectively for editing English text? 2010-08-09

    As a programmer by heart, if not by profession, I increasingly rely on, nay live in VIM for most editing-related tasks. What tips can you offer for using (almost) everyone's favorite editor for editing general-purpose text, say, an article? I mean pl

  • Regexp for Tokenizing English Text 2010-09-13

    What would be the best regular expression for tokenizing an English text? By an English token, I mean an atom consisting of maximum number of characters that can be meaningfully used for NLP purposes. An analogy is a "token" in any programming langua

  • Translating a text file from english to chinese using google translate api or other 2010-09-23

    I need to translate a text file from english to chinese using google translate api, which programming language would be feasible to do so? Or is there any other approach to do so? --------------Solutions------------- JavaScript can interface with it

  • Horizontal-scrolling text won't scroll when text is non-english 2010-11-30

    here is the website: the text of image below is english. when the text inside the "barword" div changed to non-english text , then it did not scroll or draggle. can anyone figure it out. thx. here is the css code: .s

  • Looking for English Texts for testing user possible input 2011-01-10

    Looking for English Texts for testing user possible input (with all special characters and different combination for testing proper encode end decode of user input of my website. my website have ISO-8859-1 and not utf-8) thanks, Yosef --------------S

  • English texts lexicon comparison 2011-01-23

    Let's imagine, we can build a statistics table, how much each word is used in some English text or book. We can gather statistics for each text/book in library. What is the simplest way to compare these statistics with each other? How can we find gro

  • How does the entropy of a string of English text signify low quality? 2011-02-22

    Jeff Atwood recently tweeted a link to a CodeReview post where he wanted to know if the community could improve his "calculating entropy of a string" code snippet. He explained, "We're calculating entropy of a string a few places in Stack Overflow as

  • SSIS Term Extraction for non-English text 2011-03-10

    I started learning Data Mining with SQL Server and I was curious that SQL Server Integration Services is capable to perform Term Extraction from English text. However I'm interested to perform Text Mining from non-English text, basically from Ukraini

  • My ListView consist an ImageView and a TextView i need to get the Text from the TextView 2011-03-15

    My ListView consist an ImageView and a TextView i need to get the Text from the TextView int the position of my list where i press (onItemClick). how can i do that? The 1 class have a Button then when you press i moving to the next activity (CountryV

  • Textview Width of "0dip" cutting off text inside of a TableLayout 2011-04-01

    I'm having an issue in one of my activities with text being cut-off at the first letter. The issue is, whenever navigating away from this activity to another (via the tabs at the top), and then going back to this activity, all of the text except the

  • java regex to filter out non-English text 2011-06-01

    I found a few references to regex filtering out non-English but none of them is in Java, aside from the fact that they are all referring to somewhat different problems than what I am trying to solve: Replace all non-English characters with a space. C

  • python function-converting texting language to english? 2011-06-03

    I'm having trouble creating a function that uses a dictionary of texting abbreviations, and using the dictionary to write functions that translate to and from English. For example: “y r u l8?” translates to “Why are you late?” So I have this so far:

Copyright (C), All Rights Reserved.

processed in 0.125 (s). 11 q(s)