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.

How can I convert the HTML escape sequence to a valid Java escape sequence so that I can view it?

2
  • Can you try the answers posted in stackoverflow.com/questions/13700333/… Commented Feb 6, 2017 at 2: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. Commented Feb 6, 2017 at 2:25

2 Answers 2

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"));
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I had used this sometime before, just couldn't remember that the fromHtml method existed.
0

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

2 Comments

I think this is not what he wants. He want to change all symbols possible, not exactly this .
Yeah. in general whenever I get a symbol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.