fadelakin
fadelakin

Reputation: 3843

Android Special Character: "

I'm parsing JSON from an API but in the strings I get back, I get "&qout;" For example, I have a string that is returned that says "The movie &qout;Her&qout; is a spectacular movie."

I want it to say "The movie 'Her' is a spectacular movie" but I have no idea how to update the string that is being returned from the API before I display it to the user in a TextView. The actual string in the JSON return includes &quot. I get the string through JSON parsing and I don't know if that makes things more difficult.

Any help is appreciated. Thanks.

Upvotes: 1

Views: 3563

Answers (2)

Fahad Ali
Fahad Ali

Reputation: 55

You can also use

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    Html.fromHtml("`The movie "Her" is a spectacular movie.`", HtmlCompat.FROM_HTML_MODE_LEGACY)
} else {
    Html.fromHtml("`The movie "Her" is a spectacular movie.`")
}

Upvotes: 2

Brent McFerrin
Brent McFerrin

Reputation: 528

You could always parse your string and replace the " with '

string.replace(""", "'");

I know it's not very elegant, but it gets the job done. But, along with what DIVA is asking, a valid question might be: why are you getting &quot in your JSON response from the API?

Also, you didn't mention if you were using a 3rd party JSON parser or the built in JsonReader?

Upvotes: 2

Related Questions