We often say that JavaScript supports json native, because json is a flexible application of JavaScript Object. For more information about JSON objects, see wikipedia (http://zh.wikipedia.org/zh-cn/JSON) and the official website (http://www.json.org/json-zh.html ).
We often say that JavaScript supports json native, because json is a flexible application of JavaScript Object.
Generally, we use json as the format for data exchange between the front and back ends:
In the Code logic, more is the method of associating arrays. Even so, we seldom use the object type as the key name of the key-value pair.
Var a = {}, B = [];
A [B] = new Date (); // the time value can be obtained through a [B.
Key nameCan be an object.What a wonderful thing!
But there is a problem. If you want to use this method, you need to have a condition that the data must be dynamically added. (Currently, students have no conditions to test other browsers. Currently, IE8, sogou browser's IE kernel and weikit kernel are tested)
The test code is as follows:
The Code is as follows:
Var d = document. getElementById ("hello"), obj = [1, 2], a = {obj: "test "};
A [d] = "DOMElement ";
Alert (a [obj]); // undefined
Alert (a [d]); // DOMElement
A [obj] = "Array Object ";
Alert (a [obj]); // Array Object