If the data obtained from the database (especially the description information) contains special characters, JSON is used. an error occurs when parse converts a json string to a json object, mainly because of double quotation marks and carriage return. The left angle brackets and right angle brackets also cause display problems, therefore, some special characters must be encoded or escaped before the json object is converted to the output page. The following shows the C # code encoding and escape common special characters. After the author tests and encodes and escapes these symbols, most json strings can be converted into json objects. If you encounter some problems, you should look for the problem in this direction.
TheString = theString. replace (">", "& gt;"); theString = theString. replace ("<", "& lt;"); theString = theString. replace ("", "& nbsp;"); theString = theString. replace ("\" "," & quot; "); theString = theString. replace ("\ '", "& #39;"); theString = theString. replace ("\ n", "\ n"); theString = theString. replace ("\ r", "\ r ");
Note: \ r returns to the beginning of the line, and \ n is the new line. Both of them appear at the same time and should be processed at the same time.
Supplement: line breaks in the middle of the text. spaces are not displayed in the database in the form of \ r \ n, & nbsp; (line breaks between "book" and "first 80, space between "by" and "Cao Xueqin)
Text:
Database: