I have a problem wrapping my head around a specific feature of the JSON data format.
The situation is as follows: I have a string in which Windows ( sigh ) is the directory path, backslashes are escaped. For some reason, jQuery's JSON Parser thinks that a single escape is not enough.
  & lt; Script type = "text / javascript" src = "http://ajax.googleapis.com/ ajax / libs / jQuery / 1.4.2 / jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; Var success = jQuery.parseJSON ('{"a": "b: \\\\ c"}'); Var failure = jQuery.parseJSON ('{"a": "b: \\ c"}'); & Lt; / Script & gt;   Can someone explain what is the need to avoid such a double?
 The first escape saves it in the javascript string. 
 In the JSON string it survives from the other escape. 
 Evaluates the JavaScript expression  '{"a": "b: \\ c"}'  string  '{"a": "b: \ c "} '' . 
 This string has a single unchanged  \ , which must be saved for JSON. To get the string containing  \\ , you must save each  \  in JavaScript expression, which will result in  "\\\\" . 
Comments
Post a Comment