Current location - Recipe Complete Network - Take-out food franchise - How to write json array
How to write json array
The running environment of this paper: Windows7 system, Dell G3 computer.

How to write json array:

As an array of JSON objects

【 "Google", "Runoob" and "Taobao" 】 JSON arrays are written in parentheses.

Array values in JSON must be legal JSON data types (string, number, object, array, Boolean value or null).

In JavaScript, array values can be JSON data types above or JavaScript expressions, including function, date and undefined.

Arrays in JSON objects

The value of an object property can be an array:

{

Name: website, quantity: 3, website: [Google, Runoob, Taobao].

} We can use the index value to access the array:

x = myobj . sites【0】; Cyclic array

You can use for-in to access arrays:

For (I'm in myObj.sites)

{ x+= myobj . sites【I】+“

"; } You can also use the for loop:

for(I = 0; I nested arrays in JSON objects.

An array in a JSON object can contain another array or another JSON object:

myObj = {

[Name]: "Website",

[Product number]: 3,

"Site": [

{“name“:“Google“、“info“:【“Android“、“Google search“、“Google translation“】},

{"name": "run OOB", "info": ["rookie tutorial", "rookie tool", "rookie WeChat"]},

{"Name": "Taobao", "Information": ["Taobao", "Online Shopping"]}

]

} We can use for-in to iterate through each array:

For (I'm at my obj. sites ){

x+=““+myobj . sites【I】。 name+““;

for(j in myobj . sites【I】。 Information) {

x+= myobj . sites【I】。 Information [j]+"

";

}

} Modify the array value

You can use index values to modify array values:

myobj . sites【 1】=“Github“; Delete array elements

We can use the delete keyword to delete array elements:

Delete myobj.sites [1];