views:

231

answers:

1

I am trying to convert a pretty complicated JSON string with json2.js from json.org and I keep receiving a parse error. Unfortunately I can't figure out which character it is complaining about or if I missed an escape somewhere. At this point it would be great if I could get a second pair of eyes on it. Thanks to all who help!

var jsonOriginal = "{\"type\":\"ExecuteScript\",\"id\":\"\",\"markup\":\"var scranvas = null;scranvas = lifeware.getControl('c-4246999b-11c6-44ee-8672-9654de2eb52d');scranvas.addItem('6402c984-de0d-46b3-9b0b-88cae64d21ca','<div id=\"c-6402c984-de0d-46b3-9b0b-88cae64d21ca\" class=\"container-item\" onmouseover=\"lifeware.fireEvent('6402c984-de0d-46b3-9b0b-88cae64d21ca', 'GotFocus', null);\" onmouseout=\"lifeware.fireEvent('6402c984-de0d-46b3-9b0b-88cae64d21ca', 'LostFocus', null);\" onfocus=\"lifeware.fireEvent('6402c984-de0d-46b3-9b0b-88cae64d21ca', 'GotFocus', null);\"><label style=\"position:absolute;white-space:nowrap;overflow:hidden;height:50px;width:147px;color:#FFFFFF;text-align:left;font-weight:normal;text-decoration:normal;font-style:normal;font-size:18px;font-family:Segoe UI;left:0px;display:block;filter:alpha(opacity=100);opacity:1;\" id=\"c-101a5ec4-ce1b-4ca1-bd50-c289e4d27d45\">Item 0</label></div>');\"}";
var operation = JSON.parse(jsonOriginal);
+5  A: 

the value for key 'markup' is terminated by the quote at: ...<div id=\"

usually the json encoder will handle escaping for you, e.g.:

var data = {type: 'ExecuteScript', id: '', markup: '"var... <div id="'}
var js = JSON.stringify(data)

in your example, you would want to escape the escape char so that it will be preserved and passed to parse()

<div id=\\\"
jspcal
Thanks, I didn't realize that I needed to escape the escape.
Dale Ragan