javascript - How do I escape backslashes in JSON? -
I am using Firefox's original JSON.parse () to parse some JSON strings, including regular expressions Values are included, for example:
var test = JSON.parse ('{"regex": "/ \\ d + /"}');
In the above, '\ d' throws an exception with JSON.parse (), but when I use eval (which I'm trying to escape) works fine is.
What do I need - to protect '\' in regex - are there some other JSON-friendly methods to avoid it?
You already need to avoid the backslash that escapes from there :) Like this:
var test = JSON.parse ('{"regex": "/ \\\\ d + /"}');
You can check it out here:
Comments
Post a Comment