You need to sign in to do that
Don't have an account?
Rahul Bhattad 4
How to HTML text in the body of Rest API callout
Hello,
I am trying to send HTML text in the request body for Rest API callout. I came to know that you cannot use Escape quotation marks used around HTML attributes like </br> as it breaks the JSON body. In Apex we cannout escape it by writing it like <\/ br> as it gives compilation error in class. How should I get around this situation so as to send HTML code without breaking JSON?
I am trying to send HTML text in the request body for Rest API callout. I came to know that you cannot use Escape quotation marks used around HTML attributes like </br> as it breaks the JSON body. In Apex we cannout escape it by writing it like <\/ br> as it gives compilation error in class. How should I get around this situation so as to send HTML code without breaking JSON?
On the other side, you just need to decode it.
First, your HTML is wrong. It's <br />, not </br>. The </tag> means to close an open tag (<tag>), while <tag /> means "there is no content", and is semantically equal to <tag></tag>.
Second, you simply need to JSON.serialize(htmlString) to make your string JSON-safe.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks.