The early JSON parser basically used JavaScript's eval () function. Because JSON is a javascript syntax, the eval () function can parse, interpret, and return JavaScript objects and arrays.
Ecmascript 5 standardizes the JSON parsing behavior and defines the Global Object JSON.
the JSON object has two methods: stringify () and parse (). In the simplest case, these two methods are used to serialize JavaScript objects into JSON strings and parse JSON strings into Native JavaScript. For example,
Create an HTML file: the Code is as follows: copy Code the code is as follows:
By default, the JSON string output by JSON. stringify () does not contain any blank characters or indentation. Therefore, the strings stored in jsonbook are as follows:Copy codeThe Code is as follows: {"title": "javascript advanced programming", "Authors": ["Nicholas C. zakas"], "edition": 3, "year": 2011}
When serializing JavaScript objects, all functions and prototype members are intentionally ignored and not reflected in the results. In addition, any attribute with the value of undefined will be skipped. In the result, all instance properties with valid JSON data types are final.
Note that although the book and objectbook have the same attributes, they are two independent objects with no relationship. If the string passed to JSON. parse () is not a valid JSON string, this method throws an error.