javascript - Include HTML as part of a JSON object -
i need include html , javascript value string member in json object. has got js code handy necessary escaping html can included? alternatively convert base64 still need escaping.
so if has got js escape html (which may contain javascript) escaped, appreciative. no point rolling own if there out there already.
{ "my_object": { "html": "<<div class=\"ad_box\"><img class=\"banner\" src=\"some_ad.png\"\/><h3>"hot" items<ul \/><\/div>", "item_id": 1234, "click_action":"/logaction?id=1234&type=click&info=blah", "icon":"http://my.images.com/icons/icon.png" } }
this question seems consequence of confusion appearing in "json object" expression.
there 2 different concepts :
- javascript object
- json string
there's nothing can legitimately called "json object", json string based exchange format.
when build object, don't have escaping do, myobject.myhtml = somevalue;
. when building literal object, do
var myobject = { html : '<div class="ad_box [...] </div>', [...] };
and in second step, json string
var json = json.stringify(myobject);
Comments
Post a Comment