Conversion between Json objects and Json strings (four conversion methods) _ json

Source: Internet
Author: User
There are many conversion methods between Json characters and Json objects. Next we will introduce them one by one. If you are interested, please refer to the following: 1> conversion modes supported by jQuery plug-in:

The Code is as follows:


$. ParseJSON (jsonstr); // jQuery. parseJSON (jsonstr), which can convert a json string to a json object



2> conversion modes supported by browsers(Firefox, chrome, opera, safari, ie9, ie8) and other browsers:

The Code is as follows:


JSON. parse (jsonstr); // you can convert a json string to a json object.
JSON. stringify (jsonobj); // you can convert a json object to a json string.


Note: For ie8 (compatible mode), ie7 and ie6 do not have JSON objects. We recommend using the official JSON method to introduce json. js.

3> conversion modes supported by Javascript:
Eval ('+ jsonstr +'); // you can convert a json string to a json object. Enclose a pair of parentheses outside the json character.
Note: ie8 (compatible mode), ie7 and ie6 can also convert strings into JSON objects using eval (), but these methods are not recommended, this method is not secure. eval executes the expression in the json string.

4> official JSON Conversion Method:
Http://www.json.org/with A json.js, this IE8 (compatible mode), ie7 and ie6 can support the JSON object and its stringify () and parse () methods;
You can.
Related Article

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.