在已包含单引号的json字符串中转义单引号

时间:2013-08-05 14:14:56

标签: javascript parsing escaping

我有json作为字符串存储在db中,如下所示

Json String : "{ '1': 'This is text's 1', '2': 'This is text's 2', '3': 'This : is text's 3' }"

现在在解析其给定错误时,因为它的格式不正确,应该看起来像

Json String : "{ '1': 'This is text\'s 1', '2': 'This is text\'s 2', '3': 'This : is text\'s 3' }"

这样可以很容易地解析它。

所以问题是,这种格式现在无法更改并在解析时出错:( 如果我确实替换'替换方法,它取代所有',就像这样

Json String : "{ \'1\': \'This is text\'s 1\', \'2\': \'This is text\'s 2\', \'3\': \'This : is text\'s 3\' }"

有没有什么方法可以解析它们或者首先在文本中“逃避”而不是在句子之外,然后解析它。

0 个答案:

没有答案