The conversion between JSON object and JSON string is implemented in JS

Source: Internet
Author: User
Tags string to json

for mainstream browsers (such as: firefox,chrome,opera,safari,ie8+ ), the browser provides its own JSON object, where the Parse and the stringify the method implements the conversion between a JSON object and a JSON string, for example:

    // JSON object to JSON string, output: "{\" name\ ": \" zhangsan\ ", \" age\ ": 10,\" birthday\ ": \" 2017-08-15t07:09:48.724z\ "}"    var New Date ()});     // JSON string to JSON object    var obj = json.parse ("{\" name\ ": \" zhangsan\ ", \" age\ ": 10,\" birthday\ ": \" 2017-08-15t07:09:48.724z\ "}");

Note: the date is converted to a string by international time, 8 hours less than the local time.

Some browsers may not provide JSON objects, such as:ie7,ie6 , such as, in this case, we can refer to json2.js , the JS to determine whether the browser is defined The JSON object, if not, defines the JSON object and provides the parse and stringify methods.

Json2.js source code can be obtained on GitHub, address: Https://github.com/douglascrockford/JSON-js

can also be obtained through the NuGet Package Manager , in the " Package Management Console " input command: install-package json2

The conversion between JSON object and JSON string is implemented in JS

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.