I am grabbing a string and using $.parseJSON(string) but keep getting the following error:
uncaught exception: Invalid JSON: {"0":{"chartHtml":"<p> Slide 1</p> ","presNote":"","chartOrderIndex":0},"1":{"chartHtml":"<p> Slide 2</p> ","presNote":"","chartOrderIndex":1},"2":{"chartOrderIndex":2},"3":{"chartHtml":"<p> e 3</p> ","presNote":"","chartOrderIndex":3},"4":{"chartHtml":"<p> Slide 4</p> ","presNote":"","chartOrderIndex":4},"5":{"chartHtml":"<p> Slide 5</p> ","presNote":"","chartOrderIndex":5},"6":{"chartOrderIndex":6}}
Firebug results during debug after running slideJson.d:
>>> slideJson.d
"{"0":{"chartHtml":"<p> Slide 1</p> ","presNote":"","chartOrderIndex":0},"1":{"chartHtml":"<p> Slide 2</p> ","presNote":"","chartOrderIndex":1},"2":{"chartOrderIndex":2},"3":{"chartHtml":"<p> e 3</p> ","presNote":"","chartOrderIndex":3},"4":{"chartHtml":"<p> Slide 4</p> ","presNote":"","chartOrderIndex":4},"5":{"chartHtml":"<p> Slide 5</p> ","presNote":"","chartOrderIndex":5},"6":{"chartOrderIndex":6}}"
Here is some of the call to deserialize the json:
function (slideJson) {
var slideObj, jsonStr;
if (slideJson.d) {
slideObj = $.parseJSON(slideJson.d);
Ajax call to get the Json with content type:
$.ajax({
url: 'Someurl',
type: "POST",
data: "{}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) { somenamespace.loadSlides(data); }
});
The JSON string in question ended up containing
\nand\rin thechartHTMLproperty, which by default are generated by the CKeditor.getData()method. Since i was pasting the errors from firebug they were not visible and the JSON appeared to be valid which lead to my confusion.Thanks to those who answered.