json overview

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:

  1. 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
  2. Use square brackets for arrays
  3. json object uses braces

Obtaining json data:

  1. json object.key
  2. json object["key"]
  3. Array object [index]

The way to traverse the json object:

for(var t in user){
    
    
alert(user[t]);
}
  1. t is each key in the user object currently to be traversed
  2. The obtained t is in the form of a string, so the value needs to be obtained through user[t]
  3. If you use this loop to traverse the array in the json object, then t is the index

Guess you like

Origin blog.csdn.net/zhu_fangyuan/article/details/108717944