Recently in the work, found in the IE8 under the Json.stringify () automatically translated into Unicode encoding, the original selected Chinese characters, to the background into a Unicode encoding, that is, the form of \u****. Finding the data found that, unlike the standard json.stringify (), the IE8 built-in json.stringify () automatically converts the encoding from Utf-8 to Unicode encoding, resulting in this similar garbled situation.
The solution is divided into two kinds, the first is to receive the data in the background, the data is again transcoded, re-converted to Utf-8, and then saved to the database, so that the data from the database will be removed to the front-end into the utf-8 format (that is, normal Chinese). The second is the use of eval () for transcoding in both IE8 and advanced browsers, and the final result is utf-8 encoding.
This article focuses on the second method, the use of the Eval () Transcoding method. On the MDN, the interpretation of Eval () is: eval() The argument is a string. If the string represents an expression, eval () evaluates the expression. If the parameter represents one or more JavaScript statements, then Eval () executes the statements.
var a = "Eat Xiang Xiang"; var unicodejsona = json.stringify ("a"); Unicodevar jsona = eval (' (' + Unicodejsona + ') '); Utf-8
As the code above, through eval () execution, forcibly Unicode transcoding to Utf-8, whether json.stringify () out of the result is Utf-8 or Unicode, unified into the UTF-8 format.
In fact, there is a third way to solve the problem-using json.stringify () in json2.js instead of IE8 json.stingify (). However, when a JSON object comes with a browser, the JSON object that comes with the browser is enabled instead of the JSON object in Json2.js. To solve this problem, you can change the JSON object in Json2.js to JSON2 object and change the Json.stringify () to Json2.stringify ().
The above methods can solve the problem of automatically translating Chinese into Unicode under IE8.
Solution to Json.stringify () automatic translation of Chinese into Unicode