Home>Article>Web Front-end> How to solve the javascript json garbled problem

How to solve the javascript json garbled problem

藏色散人
藏色散人 Original
2022-01-18 14:44:46 5474browse

Solution to javascript json garbled code: 1. Copy the json.js file on the json official website; 2. Introduce json into the HTML page; 3. Change the encoding method to GB2312 through "charset=GB2312".

How to solve the javascript json garbled problem

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to solve the garbled problem of javascript json?

Use of javascript json (and how to solve garbled Chinese garbled characters)

For js uses json, first go to the official website to copy the json.js file, the address is http://www.json.org/js.html

, and then import it on the page to use:

Test it Can it be used? You can write a jsp page, and then add a method to the button to pop up the processed json string.

For Chinese garbled characters, change the encoding method to: GB2312.

You can change it directly on the page or when the response returns.

How to modify the page:

  

How to modify the java code response return:

response.setHeader("Cache-Control", "no-cache"); response.setContentType("text/json;charset=gb2312");

Let’s take a look at the code below, which introduces the mutual conversion of strings and json objects: (this The example uses jquery, but it calls a button click event. 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+"/"; %>
       Insert title here
       

Recommended study: "js Basic Tutorial"

The above is the detailed content of How to solve the javascript json garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn