Decode string to valid JSON in javascript or jQuery -


i rendering string javascript variable init statements @ server side (using asp mvc, not think matters) string variable content valid json @ server side, , encoded when rendered html. rendered statement looks this:

 var myvariable = '{"prefix":"","name":"grid&... 

quatation marks , other special chars in string encoded html entities, ok, unless encoding variable declaration syntactically incorrect.

however must original string content @ client side correct json @ server side. how can accomplish javascript or jquery? (please note, know how javascript object json, not asking that)

how about?

var myjsonobject = json.parse(decodehtml(myvariable)); function decodehtml(html) {     var txt = document.createelement("textarea");     txt.innerhtml = html;    return txt.value; } 

note it's not tested

edit: tested https://jsfiddle.net/lmz20s5z/

edit2: *see console log results


Comments