嵌套JSON抛出undefined和循环

时间:2015-04-02 10:49:16

标签: jquery json html5

我有学生记录。我希望循环使用此JSON,并且使用undefined

获取SchoolRecord.classX[1]
 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]);

http://jsfiddle.net/mvxkpttg/1/

0 个答案:

没有答案