Suppose I have a server-side variable containing JSON (named strJSON
) that my own code created. In JavaScript I can consume it like this:
var data = <%= strJSON %>;
or use a JSON parsing library:
var data = JSON.parse('<%= HttpUtility.JavaScriptStringEncode(strJSON) %>');
I prefer the 2nd, for safety. Is what I’m doing unnecessary?