returning HTML in my json array, what things do I have to escape for?
views:
149answers:
3
A:
HTML can be passed in JSON if standard JSON escaping rules are applied. Any json library (worth its weight in bytes) will do this for you.
In PHP:
json_encode('<body class="foo">');
Returns
"<body class=\"foo\">"
More info on http://www.json.org/
gahooa
2009-06-10 03:00:55
A:
I think the answer is, you don't need to. JSON encoding will handling everything for you.
However, depending on your other needs, if you want to strip tags, or make < into <, then you can do so to the HTML string first, or do it at the client using Javascript.
動靜能量
2009-06-10 03:13:35
A:
You don't need to escape anything. The Json serializer will take care of it:
return Json(new { html = "<html><body><div class=\"foo\">Hello</div></body></html>" });
Darin Dimitrov
2010-08-22 10:32:59