JSON (JavaScript object Notation, JS tag) is a lightweight data interchange format. It is based on a subset of ECMAScript (the JS specification developed by the consortium) that stores and represents data in a text format that is completely independent of the programming language. The simplicity and clarity of the hierarchy makes JSON an ideal data exchange language. Easy for people to read and write, but also easy to machine analysis and generation, and effectively improve the network transmission efficiency.
The JSON key-value pair is a way to save the JS object, and the JS object is written in a similar manner, the key/value pairs in the combination of the key names in front and double quotation marks "" package, using a colon: delimited, and then the value:
This is easy to understand and is equivalent to this JAVASCRIPT statement:
The relationship between JSON and JS object Many people do not know the relationship between JSON and JS objects, and even who is not clear. In fact, it can be understood that JSON is a string representation of a JS object, which uses text to represent the information of a JS object, essentially a string. Such as
1 |
var obj = {a: ‘Hello‘ , b: ‘World‘ }; //这是一个对象,注意键名也是可以使用引号包裹的 |
1 |
var json = ‘{"a": "Hello", "b": "World"}‘ ; //这是一个 JSON 字符串,本质是一个字符串 |
JSON as a user data transmission of things, in today's web front-end development in the use of a lot, but when it is used, developers need to pay attention to a problem is how the JSON object to parse into a JS statement.
Previously, any JSON-type object could be parsed into a JS statement using the eval () method.
After HTML5 presented, there were two other methods, Stringify () and Parse (), which were specifically parsed into the JS statement for the JSON object.
There is a purpose, particularly practical, copy of the object:
With this method, the object copy can be implemented, and there is no connection between the two objects at all.
A new method of Html5--json