'New line \n in Spanned from JSON block not displaying

In Android, I'm trying to take a string from a JSON response and display it on the screen. The text may contain HTML tags, links etc so I use Spanned and it renders OK.

However, if the JSON string contains markup like \n, \r these do not get picked up when using Spanned. They do if I use a String in a textView though, but the HTML doesn't.

If I built it using SpannableStringBuilder and appended the \n, the line breaks do appear.

Are the only solutions to either (a) split the JSON string on \n and \r and append the separate parts. Or (b) to replace any such markup with a HTML line break?

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source