$.getJSON('data.json', function (data) {
$.each(data.questions, function (index, data) {
console.log(data);
});
}); // getJSON
Data JSON:
{
"questions": [
{
"qset": {
"q1": "Template 1 question1",
"q2": "Template 1 question2",
"q3": "Template 1 question3",
"q4": "Template 1 question4",
"q5": "Template 1 question5"
}
},
{
"qset": {
"q1": "Template 2 question1",
"q2": "Template 2 question2",
"q3": "Template 2 question3",
"q4": "Template 2 question4",
"q5": "Template 2 question5"
}
},
]
}
答案 0 :(得分:1)
只是验证你的json,然后尝试安装你的json properties
{
"questions": [
{
"qset": {
"q1": "Template 1 question1",
"q2": "Template 1 question2",
"q3": "Template 1 question3",
"q4": "Template 1 question4",
"q5": "Template 1 question5"
}
},
{
"qset": {
"q1": "Template 2 question1",
"q2": "Template 2 question2",
"q3": "Template 2 question3",
"q4": "Template 2 question4",
"q5": "Template 2 question5"
}
} //remove comma
]
}
答案 1 :(得分:0)
您可以尝试使用嵌套的each
循环来获取内部对象:
$.getJSON('data.json', function (data) {
$.each(data.questions, function (index, question) {
$.each(question.qset, function (index1, qset) {
console.log(qset);
});
});
});