I'm trying to loop through a JSON array, but I'm not sure how to build the each in this case properly, any ideas?
Here is the JSON that the $.get is getting:
[{"Question":"Write your question here",
"Answers":
[{"Answers":"asd",
"Correct":false},
{"Answers":"dasdas",
"Correct":true
}
]},
{"Question":"Write your question here",
"Answers":
[{"Answers":"asdasd",
"Correct":false
}
]
}]
Here is the Jquery:
$.get("data.php", function(data){
var data = data.replace(/[\[\]']+/g, '')
$.each(data, function(i, q) {
var q = new Question(count++, data.Question);
$.each(data, function(i, val) {
q.addAnswer(data.Answers, Correct, q);
});
});
questions.push(q);
});
EDIT:
$.get("data.php", function(data){
$.each(data, function(i, val) {
var q = new Question(count++, val.Question);
questions.push(q);
});
$.each(q.Answers, function(i, val) {
q.addAnswer(val, val.Correct, q);
questions.push(q);
});
});