Sending HTML Code Through JSON

The Solution to Sending HTML Code Through JSON is

Yes, you can use json_encode to take your HTML string and escape it as necessary.

Note that in JSON, the top level item must be an array or object (that's not true anymore), it cannot just be a string. So you'll want to create an object and make the HTML string a property of the object (probably the only one), so the resulting JSON looks something like:

{"html": "<p>I'm the markup</p>"}

~ Answered on 2011-02-21 10:06:04

Most Viewed Questions: