The IE8 has a built-in JSON object for working with JSON data. Unlike the standard method, the IE8 json.stringify will transcode the Utf-8 characters:
var str = "I am a programmer" var//"" \u6211\u662f\u7a0b\u5e8f\u5458 "
In general, we call this method when we send data to the server. The server side can parse correctly, so there is no problem. But if we jsonstr to use it somewhere else, we need to do some processing.
One way is to use eval:
var // "I'm a programmer."
However, when we call str more than once, is this method OK:
var str = ' I am a programmer ' var jsonstr = json.stringify (str )var// var another_parsed = eval (' (' +another_jsonstr+ ') ') //"" \u6211\u662f\ u7a0b\u5e8f\u5458 ""
It turns out to be no good, then we write a method, if we find that the result of parsing has a utf-8 code, we think that the string is not resolved completely, continue to call Eval parsing:
function Ie8parse (JSON) { var re =/\\u[0-9a-fa-f]{4}/, result = eval (' (' + JSON + ') ' while ( re.test (Result)) {= eval (' (' + result + ') } return result }
Ie8parse (ANOTHER_JSONSTR)//"I am a programmer"
Another method is to do some processing of the IE8 Json.stringify method and convert the Utf-8 code in the converted string back to the character:
function Stringify (object) { var string = json.stringify (object) return String.Replace (/\\u ([0-9a-fa-f]{2,4})/g,function(string,matched) { return String.fromCharCode (parseint (matched,16) }) }
In this way, you can solve the IE8 json.stringify automatic conversion utf-8 characters caused by the inconvenience.
Solutions for automatic conversion of Unicode characters by json.stringify method in IE8