在这种情况下如何设置多级 JSON?
var quiz = {};
for(var i = 0; i < questions.length; i++) {
quiz['Questions'] = {
Question: Question,
Answers: Answers,
Correct: Correct
};
};
json_quizModule = JSON.stringify({QuizModule: quiz }, null, "\t");
alert(json_quizModule)
现在所有这些都在参数“问题”下。但我尝试实现 JSON 的这种结构:
{
"QuizModule": {
"Questions": {
"Question": "Write your question here"
{ "Answers": "sds"
{ "Correct": false
}
}
}
}
}
我对 JSON 很陌生,如果有多个问题,是否也可以有几个参数名称“问题”?
真的很感谢这里的一些帮助!
更新:
查询:
var quiz = {};
var quiz = {
Questions: []
};
for(var i = 0; i < questions.length; i++) {
var q = questions[i];
var answers = q.getAnswers()
quiz.Questions.push({
Question: q.getQuestion()
});
for(var n = 0; n < answers.length; n++){
var quiz = {
Answers: []
};
quiz.Questions.Answers.push({
Answers: answers[n].getAnswer(),
Correct: answers[n].getCorrect()
});
}
}