James Krawczyk James Krawczyk - 4 days ago 6
Android Question

Android JSON Translate HTML Entities

I'm trying to pull a JSON output and populate a ListView with it. Everything is working, except the resulting text has html entities in it instead of the symbols, for example £ is

£
and - is
–


I've looked at the JSON feed output manually, via the url, and it's not showing the entities but is showing £ and - and such.

The code the populate the ListView is,

ListAdapter adapter;
adapter = new SimpleAdapter(
MainActivity.this, productsList,
R.layout.list_row, new String[] { TAG_BODY, TAG_TITLE},
new int[] { R.id.id, R.id.headline });
// updating listview
setListAdapter(adapter);


I've found a few answers around but they all consist of either fixing on server, (which is outputting fine in this case), or using WebView which I'd rather not do.

Answer

Probably too late but here is how you do it

if (Build.VERSION.SDK_INT >= 24)
        {
           textView.setText(Html.fromHtml(htmlString , Html.FROM_HTML_MODE_LEGACY)));
           textView.setText(Html.fromHtml(htmlString , Html.FROM_HTML_MODE_LEGACY)));

        }
        else
        {
            textView.setText(Html.fromHtml(htmlString));
            textView.setText(Html.fromHtml(htmlString));
        }

Here is an article about handling HTML in JSON output

Comments