S
S
s_pyanov2018-02-05 03:44:04
JavaScript
s_pyanov, 2018-02-05 03:44:04

Why are quotes not escaped in JSON.parse?

Good day to all.
I ran into a problem: in the th application I send json to the page

{"art_slice":[{"title":"Заголовок","content":"Содержимое статьи"},{"title":"Заголовок второй статьи","content":"Содержимое второй статьи"}]}

On the page, I try to parse the response through JSON.parse, it looks like this in the source code of the page
const resolve = "{"art_slice":[{"title":"Заголовок","content":"Содержимое статьи"},{"title":"Заголовок второй статьи","content":"Содержимое второй статьи"}]}"
    const user = JSON.parse(resolve);

It turns out that quotes are not escaped. But when constructing
$scope.x = angular.fromJson("{\"art_slice\":[{\"title\":\"Заголовок\",\"content\":\"Содержимое статьи\"},{\"title\":\"Заголовок второй статьи\",\"content\":\"Содержимое второй статьи\"}]}");

quotes are escaped by angular.
In both pieces, the response from the th server is sent to the page in the form
Why such a different behavior?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
s_pyanov, 2018-02-07
@s_pyanov

If you insert the output from the template (through {{.}}) in the body tags, then everything is displayed on the page as it should

{"art_slice":[{"title":"Заголовок","content":"Содержимое статьи"},{"title":"Заголовок второй статьи","content":"Содержимое второй статьи"}]}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question