0

I am receiving a string using REST APIs.

JSONObject obj = new JSONObject(output);
JSONArray contacts = obj.getJSONArray("results");
JSONObject result = contacts.getJSONObject(0);
..
String brandName = result.getString("productName");

In some cases productName comes as Dri-FIT™ Element Half Zip.

I want to show it as "Dri-FIT™ Element Half Zip" in Android, but it shows up in the TextView as Dri-FIT™ Element Half Zip.

Can anyone help me as to how to convert the HTML escape sequence to a valid Java escape sequence so that I can view it?

Anindya Dutta
  • 1,972
  • 2
  • 18
  • 33
  • Can you try the answers posted in http://stackoverflow.com/questions/13700333/convert-escaped-unicode-character-back-to-actual-character – GrabNewTech Feb 06 '17 at 02:20
  • @GrabNewTech, no that answers for elements where I have \uHex number. But that is what I want. right now I am getting it in HTML form. – Anindya Dutta Feb 06 '17 at 02:25

2 Answers2

1

You can try this. I think this is the best way to show your special symbol.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            tv.setText(Html.fromHtml("Dri-FIT™ Element Half Zip", Html.FROM_HTML_MODE_COMPACT));
        }else{
            tv.setText(Html.fromHtml("Dri-FIT™ Element Half Zip"));
        }
Harry T.
  • 3,478
  • 2
  • 21
  • 41
0

Please replace &#8482 to \u2122 (2122 is hex for 8482)

Richard LIANG
  • 171
  • 2
  • 2