Definition: JSON is a JavaScript object notation.
Format:
var jsonobject ={
"url": "Www.baidu.com",
"Name": "Zkr",
"Address": "Shanghai"
}
Nested JSON multiple times:
var jsonobject={
"CH":
[
{"Names": "Yi Mei Homeland", "Data": [2,2,1,1,1,1], "Times": [10,11,13,13,21,23]},
{"Names": "Yi Mei Homeland", "Data": [2,2,1,1,1,1], "Times": [10,11,13,13,21,23]}
]
} ;
Basic syntax:
exists in the form of a value pair (name: value pair) key value;
If the value pair has multiple objects in the array [], each object is denoted by {}, and the key-value pairs are: separate;
Simple examples of use;
<script type= "Text/javascript" >
var jsono={
"Name": "Zkr",
"Age": 12,
"Hight": 165
"Adress": {
"China": "Guo",
"Jiangsu": "Sheng",
"Nanjing": "Shi"
}
}
Window.onload=function () {
document.getElementById ("name"). Innerhtml=jsono.name;
document.getElementById ("Age"). Innerhtml=jsono.age;
document.getElementById ("Hight"). Innerhtml=jsono.hight;
alert (JsonO.adress.china);
Alert (jsono.adress["Nanjing"]);
}
</script>
<div>
Name:<span id= "Name" ></span>
Age:<span id= "Age" ></span>
Hight:<span id= "Hight" ></span>
</div>
How to access JSON:
Through the form of., such as: Jsono.name;
In the form of ["name"],[array subscript], such as: jsono["name"], jsono["age"],jsono["hight"];
For nested JSON objects:
can use
JsonO.adress.china;
jsono.adress["Nanjing"];
Modifying the value of JSON
Jsono.adress.china= "Zhongguo";
jsono.adress["Nanjing"]= "Shenghui";
To delete an object's properties:
Delete keyword:
Delete JsonO.adress.china;
Delete jsono.adress["Nanjing"];
JSON Learning Notes