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