The js data format of Baidu 3D map: mapData["sign"] ["5,158,141"]={"busStation":{"4,317,282": [{"id":"ff8080811c462eb7011d2e23d5b91083","name":"Di'anmen Station" ,"y":579152,"x":650606}, {"id":"ff8080811c462eb7011d2e2414f31085","name":"Di'anmen Station","y":579176,"x":650750}],"4,316,283 ": [{"id":"ff8080811c462eb7011d2cc3d5630ef3","name":"白石站","y":580232,"x":648834}]}}
Let's imitate, first understand The concept of an object as an associative array:
var o = new Object();
o.x="Hello!";
We defined an object above, and one of the attributes of the object is x. This form is Common to us. Objects in JavaScript can be used as associative arrays because they can associate any data value with any string. If you use objects in this way, then the object to be accessed must use a different syntax, that is, use a string enclosed by square brackets and containing the required attribute name. Using this syntax we can change the o object above The x attribute is assigned as follows:
var o = new Object();
o["x"]="Hello!"
This method is necessary in some cases, such as when you If you don't know the attribute name, you cannot use "." to access the object's attributes, but you can use the operator [] to name the attribute, because its attribute name is a string value (the value is dynamic, in can be changed at runtime), rather than an identifier (which is static and must be hard-coded in the program). If an object is used in this way, we call it an associative array. (For details, see "The Definitive Guide to JavaScript (Fourth Edition)" (page 155))
Through the above description, we can define an object like this:
(1)
( 2) We can also write the form of the object as follows:
At this point, our js data is the same as on Baidu.