The JSON string that was returned in the background today was wrong, and a textarea was found to have a newline in the submitted field.
Error reason: Json.parse to JSON string encountered some special characters need to be escaped first,
Can be escaped with str.replace (/\n/g, "\\\\n"), ' \ \ ' to a single ' \ ', ' \\n ' to ' \ n ', and finally to ' \\n ' so that it can be converted to an object with parse to ' \ n ', the extracted string is set to the HTML text \ N is parsed as a newline.
The ECMA script indicates the characters in the JSON string that need to be escaped:
Test:
1.var kks= "{" id ": 2," name ": null}" Reviver traversal of the first two is the key value in the JSON string, the null value temporarily does not know what is (Prototype object?). )。
2.json string has a value of undefined parsing will error
2.json.stringify ignores objects with a value of undefined
Syntax: The value of undefined is not included in the scope can be resolved, so will error, haha.
Reference: The English version of the ECMA specification: HTTP://WWW.ECMA-INTERNATIONAL.ORG/ECMA-262/5.1/
English: http://lzw.me/pages/ecmascript/#611
Json.parse parsing JSON string, error in line break