我是JSON和jQuery的新手,目前在将JSON文件中的数据检索到使用.getJSON()
函数的javascript文件时遇到问题。我不相信我编码的是正确的,我不知道要改变什么。这两个文件都在同一个文件夹中,这都是在XAMPP上运行的。我目前的.getJSON
功能是:
var url = 'http://localhost/atriviagame/database.json';
$.getJSON(url, function(json) {
var questions = json.questions;
});
我当前的JSON文件是:
{
"questions": [{
"question": "Which list contains words that are NOT names of shoe types:",
"choices": ["A. Oxford, jelly, boat, clogs, stiletto, mary jane",
"B. Loafer, gladiator, wedge, mule, platform",
"C. Pump, moccasin, wingtip, sneaker, derby, monk",
"D. Chalupa, dogler, hamster, croonley, frankfurt",
" "
],
"correctAnswer": 3
}]
}