我想訪問嵌套的JSON,例如JSON訪問和搜索嵌套對象使用jQuery
var SchoolData = {
"SchoolRecord": {
"classX": {
"name": "Student Name 1",
"subject": {
"mathsDept": {
"subject": "Maths",
"marks": 87
},
"scienceDept": {
"subject": "Physics",
"marks": 55
},
"socialDept": {
"subject": "Social",
"marks": 95
}
}
},
"classIX": {
"name": "Student Name 2",
"subject": {
"mathsDept": {
"subject": "Maths",
"marks": 99
},
"scienceDept": {
"subject": "Physics",
"marks": 95
},
"socialDept": {
"subject": "Social",
"marks": 91
}
}
}
}
}
console.log(SchoolData.SchoolRecord);
console.log(SchoolData.SchoolRecord[0]);
這裏是一個FIDDLE。
我想在JSON數據標記SchoolData.marks
'SchoolData.SchoolRecord.classX.subject.mathsDept.marks' – adeneo 2015-04-02 17:10:51
您必須遍歷每個屬性 – adeneo 2015-04-02 17:11:08
我不想按對象訪問,我希望在一個語句中使用classX和classIX記錄 – 2015-04-02 17:11:56