In the case of data extracted from the database (especially descriptive information) containing special characters, There is an error when converting a JSON string into a JSON object using Json.parse. It is mainly double quotes, carriage return, and so on, and left angle brackets and right angle brackets can also cause problems, so to encode or escape some special conformance before outputting to the page for JSON object conversion, the following shows the C #代码编码和转义几个常用特殊字符. After the author tests, after encoding and escaping these symbols, most of the JSON strings can be converted to JSON objects. If you encounter individual problems, you should look for the problem in this direction.
TheString = Thestring.replace (">", ">");
TheString = Thestring.replace ("<", "<");
TheString = Thestring.replace ("", "");
TheString = Thestring.replace ("\" "," "");
TheString = Thestring.replace ("\", "'");
TheString = Thestring.replace ("\", "\\\\");//The Escape of the slash
thestring = thestring.replace ("\ n", "\\n");
TheString = Thestring.replace ("\ r", \ r);
Note: \ r is back at the beginning, \ n is the Le line, these two generally appear simultaneously and should be processed at the same time.
Add: Text in the middle of the line, the space in the database is not to \ r \ n, etc form display ("book" and "Top 80" between the line, "from" and "Cao Xueqin" space)
Text:
Database: