Use of JavaScript JSON (and Chinese garbled characters)

Source: Internet
Author: User

For JS using JSON, first copy the JSON. js file to the official website, address http://www.json.org/js.html

Then you can use the following code on the page:

<SCRIPT type = "text/JavaScript" src = "JSON. js"> </SCRIPT>

Test whether it can be used. You can write a JSP page and add a method to the button. The processed JSON string is displayed.

For Chinese garbled characters, the encoding method is changed to gb2312.

You can change the value on the page or when the response is returned.

Modification of the page:

<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>

Java code Response Return correction:

Response. setheader ("cache-control", "No-Cache ");
Response. setcontenttype ("text/JSON; charset = gb2312 ");

Let's take a look at the code and introduce the conversion between strings and JSON objects: (jquery is used in this example, but a button click event is called. You can change it to onclick)

<% @ Page Language = "Java" pageencoding = "UTF-8" %> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> 

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.