我有一些应用程序。以下是我从服务器上获得的考试答案(这是一种在线考试方式)。
考试将包含部分和部分将包含问题。给定响应包含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部分所示的section对象。
我想以同样的方式访问该部分的问题
alert(resData.exam_section_id[i].section_ques_id[0]);
这里的技巧是,将动态生成对象的名称(这是部分ID和问题ID)。
任何人都可以帮助我了解如何访问这些对象。