Javascript JSON.parse function with Ajax request and "\\n" new line escaped char -


https://jsbin.com/zuhatujoqo/1/edit?js,console

edit: json file has line:

{"pd":"ciao \\n ste"} 

i'm requesting valid json file ajax call.
json.parse result.

i don't understand happening "\\n" escaped new line char coming json file.

json.parse giving me different result if feed same values.

var result = json.parse(data); console.log(result); var result2 = json.parse('{"pd":"ciao \\n ste"}'); console.log(result2); 

as understand may related fact javascript before , parse escaping ( or unescaping ?? ) string.

the problem don't understand this:

result = result.replace(/\\n/g, "<br />"); 

do have escape regex itself?

sum: want use .json file loaded via ajax. want json.parse job , unescape "\\n" returning newline char.

thanks answers bergi gave me, understand json.parse doing job. fault, providing json file "\\n" inside instead of "\n".

here updated jsbin can see json.parse acts same in different scenario. https://jsbin.com/xezipucili/1/edit?js,console


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -