0

我有一个这样的结果json

[
       {"courseStarted" :[
               {"CategoryName":"CategoryName","courseName" :"Equipment Course", "seriesName": "Free Education", "courseDetails" :[
                       {"totalLessons" :"2", "NoLessonComplete":"1", "lastviewed":"date", "lessonDetails":[
                               {"lessonId":"342367","quiz":"quizReady"},
                               {"lessonId" :"345345", "quiz":"quizReady"},
                               {"lessonId":"435435","quiz":"quizReady"},
                               {"lessonId":"4234234", "quiz":"quizFailed"},
                               {"lessonId":"4234234","quiz":"quizPassed"}
                       ]}
               ]}
       ]},
       {"courseStarted" :[
               {"CategoryName":"CategoryName","courseName" :"Equipment Course1", "seriesName": "Free Education1", "courseDetails" :[
                       {"totalLessons" :"21", "NoLessonComplete":"11", "lastviewed":"date1", "lessonDetails":[
                               {"lessonId":"3423671","quiz":"quizReady"},
                               {"lessonId" :"3453451", "quiz":"quizReady"},
                               {"lessonId":"4354351","quiz":"quizReady"},
                               {"lessonId":"42342341", "quiz":"quizReady"},
                               {"lessonId":"42342341","quiz":"quizPassed"}
                       ]}
               ]}
       ]}

    ]

从此 json 输出中,我如何使用 $.each 函数访问 courseId 的值。

4

1 回答 1

1
$.each(data, function(){

    // Print course name
    console.log(this.courseStarted[0].courseName);

    $.each(this.courseStarted[0].courseDetails[0].lessonDetails, function(){
        // Print lesson id
        console.log(this.lessonId);
    });

});
于 2012-06-11T19:24:00.477 回答