【发布时间】:2015-12-26 03:24:17
【问题描述】:
所以,我需要将以下代码放入 JSON 文件中,并将其加载到单独的 JavaScript 文件中:
var allQuestions = [{
question: "What is Elvis Presley's middle name?",
choices: ["David", "Aaron", "Eric", "Jack"],
correctAnswer: 1
}, {
question: "Who is the singer of the Counting Crows?",
choices: ["Adam Duritz", "John Adams", "Eric Johnson", "Jack Black"],
correctAnswer: 0
}, {
question: "Who is the Queen of Soul?",
choices: ["Mariah Carey", "Whitney Houston", "Aretha Franklin", "Beyonce"],
correctAnswer: 2
}, {
question: "Which famous group was once known as The Quarrymen?",
choices: ["The Beatles", "The Birds", "The Who", "Led Zeppelin"],
correctAnswer: 0
}];
换句话说,allQuestions 的内容需要放在一个 JSON 文件中,然后加载到一个单独的 JavaScript 文件中的 allQuestions 变量中。 JSON 文件会是什么样子?如何将其加载到 allQuestions 变量中?
【问题讨论】:
标签: javascript jquery json