I am trying to store a JSON string inside an ASP.NET Literal Control. This JSON string is in this format:
[
['Time', 'Speed', 'Distance'],
['09-07-2015 2:21:39 PM', 76, 500],
['08-07-2015 6:02:41 PM', 350, 500],
['08-07-2015 5:55:43 PM', 10, 50],
['08-07-2015 5:55:36 PM', 50, 50],
['08-07-2015 5:55:21 PM', 180, 80],
['08-07-2015 5:51:38 PM', 100, null]
]
This is how I am adding it to literal:
Literal1.Text = "<input type='hidden' id='jsondata' value=\"" + JSONData + "\" />";
But actual JSON data that will be entered by the user may contain any character including " and '. And this JSON data is accessed inside JavaScript like:
function SetGraphData() {
var hiddenField = $('#jsondata');
jsonData = $.parseJSON(hiddenField.val());
}
But when parsing JSON, it's showing me Invalid character error. Please tell me what can be the reason?