I'm trying to get the values from a JSON file with "$.each" below but it doesn't give me any values with the $.each method I Use below, do anyone have any suggestions how I can make this work properly? I want to get information for each object [Question] with Question value and then answers for each question.
JSON:
[
{
"Question": "Question 1",
"Answers": [
{
"Answers": "Answer 1",
"Correct": false
},
{
"Answers": "answer2",
"Correct": true
}
]
},
{
"Question": "Question 2",
"Answers": [
{
"Answers": "An Answer",
"Correct": false
}
]
}
]
jQuery:
$(document).ready(function () {
$.get("data.php", function(data) {
$.each(data, function(i, val) {
var q = new Question(count++, val.Question);
questions.push(q);
});
$.each(val.Answers, function(i, a) {
q.addAnswer(a.Answers, a.Correct, q);
questions.push(q);
});
});
Thankful for any help!
UPDATE:
$(document).ready(function () {
$.get("data.php?campaign_id=39&social_user_id=1192&edit=true", function(data){
var questions = [];
$.each(data, function(i, val) {
var q = new Question(count++, val.Question);
questions.push(q);
$.each(val.Answers, function(i, a) {
q.addAnswer(a.Answers, a.Correct, q);
});
});
});
});