When using JSON strings to return large amounts of rich text data to the server, you need to be aware of the problems that have been encountered during the recent development.

Source: Internet
Author: User

There are regular user input strings in the JSON string, and a lot of rich Text style tags (users cannot see directly, click the HTML Source button in the rich Text editor to see), such as the following:

<p><strong> Rich Text &LT;&GT;SAD&LT;SPAN&GT;ADZX I am user input </strong></p>

<p><span><span style= "font-family: Microsoft Black, & #39; Microsoft yahei& #39;;;" > Rich Text &lt;&gt;sad&lt;span&gt;adzx I'm a user input </span><br/></span></p>

For example, in this case, you need to send the above string through a JSON format, post to the server side, assuming that the string is assigned to variable a:

The structure of the post parameters is this:

{"params": {"Content": A}}

The premise is that the text content of the back-end post needs to contain rich text styles, which is why the Rich text editor is used for the purpose.

It can be noted that the above string, the black bold part, the Rich text editor will automatically do the encodehtml operation, that is, the regular user input string, and the red word part is the Rich Text style label section.

In the sample, the rich Text area contains: <span style= "font-family: Microsoft Black, & #39; Microsoft yahei& #39;;;" > This string, because the JSON format used to back-end post data, so need to pay attention to escape the double quotation mark ", otherwise it will cause the back-end parsing JSON error, so do a bit of escaping, the single double quotation marks into the \\\" This form (because it also involves the operation of encodeURI and decodeURI).

At the same time, the user may enter a single or multiple \ backslash (escape character), so it is also the same escape processing, the individual backslash, into the form of \\\\.

In the final analysis, JSON is used to post large amounts of data (Rich text data) to the server, so it involves the handling of two special characters, double quotes and backslashes.

When using JSON strings to return large amounts of rich text data to the server, you need to be aware of the problems that have been encountered during the recent development.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.