json和陣列的巢狀練習

2022-08-30 13:36:09 字數 2650 閱讀 5633

---恢復內容開始---

今天學習了json和陣列的巢狀,例如var a=,

"wenke","like"為a的key,類似陣列的下標,可以自定義,也方便儲存一些資訊,其中a["like"]為乙個陣列,當我們想輸入「數學」的時候,可以這樣取出:

alert ["like"][0];

做個複雜一點的例題:

設計乙個json 將下面所有資訊儲存起來,有三個年級,每個年級三個班,每個班有三個學生,學生資訊如下:

小紅  女  15

家屬:紅1     女   16

紅2 女   17

紅3 女   18

小明  男  16

家屬:明1     男   17

明2 男   18

明3 男   19

小剛  男  30

家屬:剛1  男  31

剛2  男  32

剛3  男  33

var a =

一年級:

一班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

二班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

三班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

二年級:

一班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

二班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

三班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

三年級:

一班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

二班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

三班:xiaohong:["小紅","女",15,[["紅1","女",16],["紅2","女",17],["紅3","女",18]]],

xiaoming:["小明","男",16,[["明1","男",17],["明2","男",18],["明3","男",19]]],

xiaogang:["小剛","男",30,[["剛1","男",31],["剛2","男",32],["剛3","男",33]]]

//如果我們要取出一年級二班小剛的家屬剛1的年齡

console.log(a["一年級"]["二班"]["xiaogang"][3][0][2]);

spark解析巢狀JSON陣列

資料是帶有時間戳的json陣列 資料格式 1610352196000 data data 讀取 val tmp sc.textfile in test json.log tmp.foreach println 列印資料 json陣列可根據 n timeserver n timeserver n ti...

指標和陣列的練習

首先做這些練習前我們要明白陣列名的意義 1.sizeof 陣列名 這裡的陣列名表示整個陣列,計算的是整個陣列的大小,單位是位元組。2.陣列名,這裡的陣列名表示整個陣列,取出的是整個陣列的位址。3.除此之外所有的陣列名都表示首元素位址。而位址的大小都是4 32為平台 8 64位平台 個位元組。ps 本...

json和陣列得區別

json的定義 json和陣列得區別 undefined出現的情況 1.沒有定義 2.定義了沒有賦值 js命名規範及必要性 可讀性 能看懂 規範性 符合規則 引數 把值傳到函式裡面來 返回值 把函式一些值傳到外面來 argument像陣列 並不是真正的陣列,是乙個agruments物件 有lengt...