0

我有一些应用程序。以下是我从服务器获得的考试响应(这是一种在线考试)。

考试将包含部分,部分将包含问题。给定的响应包含 2 个部分

{
"Success": true,
"Message": "Questions list",
"Response": {
    "c_exam_name": "Verbal-Math",
    "exam_section_id": [
        "SCjnqwh4vcng",
        "SCasqdesml6k"
    ],
    "section_ques_id": [
            "QUpg4r4s3by0w500",
            "QUcurdy54uzq5vsh",
            "QUmj8hsj0ulbff4p",
            "QU1a6zdiiq9zt347"
        ],
    "SCjnqwh4vcng": {
        "c_section_max_time": "7",
        "c_section_total_ques": 15,
        "QUpg4r4s3by0w500": {
            "c_q_type": "Multiple Option",
            "c_ques_info": {
                "question_info": {
                    "question": "<p>Poe's _______ reviews of contemporary fiction , which often find great merit in otherwise ________ literary gems, must make us respect his critical judgment in addition to his well-known literary talent.<\/p>",
                    "option_a": "thorough . . completed",
                    "option_b": "petulant . . unpopular",
                    "option_c": "insightful . . unappreciated",
                    "answer": "option_c"
                }
            },
            "c_section_id": "SCjnqwh4vcng"

        },
        "QUcurdy54uzq5vsh": {
            "c_q_type": "Multiple Option",
            "c_ques_info": {
                "question_info": {
                    "question": "<p>The significance of the Magna Carta lies not in ________ provisions, but in its broader impact : it made the king subject to the law.<\/p>",
                    "option_a": "specific",
                    "option_b": "revolutionary",
                    "option_c": "implicit",
                    "answer": "option_a"
                },
                "user_ans_info": "",
                "c_section_id": "SCjnqwh4vcng"
            }
        },

我正在访问 section 对象,如下所示:

success: function (msg) {
    resData = msg.Response;
    for (i = 0; i < msg.Response.exam_section_id.length; i++)
    {
        alert(resData.exam_section_id[i]);
        localStorage.setItem(resData.exam_section_id[i],
                             JSON.stringify(resData.exam_section_id[i]));

    }
}

alert(resData.exam_section_id[i]);给出部分字符串 id。我如何访问下图中表示为第 1 部分的部分对象。我想以同样的方式访问该部分的问题

alert(resData.exam_section_id[i].section_ques_id[0]);

这里的技巧是,对象的名称将动态生成(即部分 ID 和问题 ID)。

任何人都可以帮助我了解如何访问这些对象。

4

0 回答 0