1. Concept
Concept: JavaScript Object Nation, js object notation
Function: Mainly realize the storage and exchange of information
Features: fast speed, small footprint, easy to analyze
Syntax: The data in json consists of key-value pairs.
Key: Enclosed by double quotes or single quotes.
Value: numeric value (decimal, integer), string, boolean (false, true)
eg:
{
"name" : "zs","age" : 20,"gender" : false }
Array: Array [element 1, element 2...]
{
"users" : [
{
"name" : "zs","age" : 20,"gender" : false },
{
"name" : "ls","age" : 21,"gender" : true },
{
"name" : "ww","age" : 20,"gender" : true },
...
]}
json object:
- The data content consists of key-value pairs, which are connected by colons, and the key-value pairs and key-value pairs are separated by commas
- Use square brackets for arrays
- json object uses braces
Obtaining json data:
- json object.key
- json object["key"]
- Array object [index]
The way to traverse the json object:
for(var t in user){
alert(user[t]);
}
- t is each key in the user object currently to be traversed
- The obtained t is in the form of a string, so the value needs to be obtained through user[t]
- If you use this loop to traverse the array in the json object, then t is the index