Encoding in Android TextView

I am new to Android.
When using Json Parsing, I had a problem displaying text (maybe using a font, I don’t know).
This is my Json answer:

{"Response":[{"Id":829,"Name":"Tiền không đem lại hạnh phúc nhưng...","ShortDescription":"Một tỷ phú tâm sự với bạn,... 

But when I understand TextView in android, the “Name” becomes:

  "Tiá» n không Ä'em lại hạnh phúc nhưng..." 

This text is in Vietnamese. How can i fix this?

+6
source share
3 answers

I fixed it. My problem is UTF-8 encoding.

 String name = ""; try { name = new String(c.getString("NAME").getBytes("ISO-8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String decodedName = Html.fromHtml(name).toString(); 
+18
source

Use webView to display text as follows:

 myWebView.loadData(myHtmlString, "text/html; charset=UTF-8", null); 
+4
source

The problem you are getting is actually encoding. So, the json string you get from your answer needs to add the correct encoding format. So just do it like this.

Enabling json publishing as

 StringEntity strEntity = new StringEntity(Your_json_string, HTTP.UTF_8); 

When using json object use this

  if (statuscode == HttpStatus.SC_OK) { String responseStr = EntityUtils.toString(response.getEntity(), HTTP.UTF_8); 
0
source

Source: https://habr.com/ru/post/954379/


All Articles