We often say that JSON is a lightweight data format.
JSON can represent three types of values: Simple values, objects, arrays
Writing in JSON object format:
{"Name": "JSON", "language": "JavaScript"}
Note: JSON attribute names must be enclosed in double quotation marks.
JSON array Format:
[+, "JSON", true]
Note: There is no concept of variables and semicolons in the JSON data format.
JSON data can be parsed and serialized by a wide range of programming languages, such as JavaScript;
In ECMAScript5, JSON is defined as a global object, with two of the most important
Methods: Json.stringify () and Json.parse ()
1) json.stringify () serializes the JavaScript object into a JSON string;
2) Json.parse () parses the JSON object into a JavaScript string
var book={ title: "JavaScript" }var jsontext = json.stringify (book); The value of Jsontext is: { "title": "JavaScript"}
var stringtext = Json.parse ( { "title": "JavaScript" }); The value of Stringtext is: { "title": "JavaScript"}
JSON serialization also has more advanced usage, which can be used to check data.
Advanced usage of Json.parse () parsing:
<script>varBook = { "title": "JSON", "Author": "Hzl", Date:NewDate (2014,10,11) }; varJsontext =json.stringify (book); Console.log (Jsontext); varStringtext = Json.parse (Jsontext,function(key, value) {if(Key = = "Date"){ //Console.log (value); return NewDate (value); }Else{ returnvalue; } }); Console.log (Stringtext); //Console.log (StringText.date.getFullYear ());</script>
View Code
Understanding of JSON data format