One, {} curly braces that define an object, most of the cases have a pair of properties and values, or functions.
such as: var Langshen = {"Name": "Langshen", "Age": "28"};
It declares an object named "Langshen", separated by a number of properties or functions (commas), because it is an object's property.
So when you visit, you should use. (point) to layer access: Langshen.name, Langshen.age, of course, we can also use an array of ways to access, such as: langshen["Name", langshen["age"], the result is the same.
This writing, in the JSON data structure is often used, in addition, we usually write the function group, also often used, such as:
Copy Code code as follows:
var langshen = {
Name = function () {
return "Langshen";
},
Age = function () {
Return "28";
}
}
Call the same way, because it is a function group, so add (), such as: Alert (Langshen.name ());
two, [] brackets, which represent an array, can also be understood as an array object.
such as: var langshen = ["Name", "Langshen", "Age", "28"];
Obviously, each value or function is independent, with multiple values separated by only, (comma), because it is an array object, so it equals:
var langshen = Array ("Name", "Langshen", "Age", "28");
When accessing, it is also an array, alert (langshen[0]);
three, {} and [] used together, we said, {} is an object, [] is an array, we can form an array of objects, such as:
Copy Code code as follows:
var langshen = {"Name": "Langshen",
"Mywife": ["LuLu", "26"],
' Myson ': [{' Name ': ' Son1 '},{' name ': ' Son2 '},{' name ': ' Son3 '}]
}
From the structure above, the first item in an object is an attribute, the second is an array, and the third is an array containing more than one object. Called, is also a layer of access, the object's properties with the. (dot) overlay, the array is accessed by [subscript].
such as: Alert (langshen.myson[1). Name);