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>