Development in the web often comes across processing JSON strings, typically in two ways:
One is the JSON string to the object, usually by the background JSON string from the foreground JS to get the object, this situation can call
The eval (' (' + jsonstring+ ') method is converted to an object, and then through the object. property to get the value;
The second is the object to JSON string, usually there is a JS get object to JSON string to the background, this can call Json.stringify (jsonstring) to get the JSON string, but if there is Chinese, Chinese will be converted to Unicode encoding format, If you want to display Chinese, you need to do Unicode transcoding, the specific transcoding method is as follows:
gb2312unicodeconverter.togb2312 (Json.stringify (jsonstring))
var gb2312unicodeconverter = {
Tounicode:function (str) {
return Escape (str). toLocaleLowerCase (). Replace (/%u/gi, ' \\u ');
}
, Togb2312:function (str) {
Return unescape (Str.replace (/\\u/gi, '%u '));
}
};
All of these are processed by native JS, and can also be handled by Json.js.
This article from "beyond their own" blog, reproduced please contact the author!
JavaScript processing for JSON