JavaScript processing for JSON

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.