这是我的JSON数据 -
allsurvey[
{eachquestion:
[{question:sdvsd,
answeroptions:[fsdf,sdf],
questiontype:multiChoice},
{question:sdf,
answeroptions:sdf,
questiontype:textbox}],
noofques:2,
surveytitle:aaaa
}
]
我想访问数组中的值" eachquestion"即问题,答案选项
答案 0 :(得分:1)
可能的数据结构可能就是这样。我添加了一个可以访问项目的示例:
var object = {
allsurvey: [{
eachquestion: [{
question: 'sdvsd',
answeroptions: ['fsdf', 'sdf'],
questiontype: 'multiChoice'
}, {
question: 'sdf',
answeroptions: 'sdf',
questiontype: 'textbox'
}],
noofques: 2,
surveytitle: 'aaaa'
}]
};
object.allsurvey.forEach(function (a) {
a.eachquestion.forEach(function (b) {
document.write(Object.keys(b).map(function (k) {
return k + ': ' + b[k];
}).join('<br>'));
document.write('<hr>');
});
});