How can I access the data from a JSON array in Javascript
New to JSON and wanting to set up a site where I could pull quiz data from a separate json file into my site - but it's giving me a hard time. Could someone give me some suggestions please?
Here's my JSON file -
[
{
"question1": "question1",
"answer1": [
{
"correct1": "correct1"
};{
"incorrect1": "incorrect1"
};{
"incorrect2": "incorrect2"
};{
"incorrect3": "incorrect3"
};
]
},
{
"question2": "question2",
"answer2": [
{
"correct1": "correct1"
};{
"incorrect1": "incorrect1"
};{
"incorrect2": "incorrect2"
};{
"incorrect3": "incorrect3"
};
]
}
]
And here is a summary of the html page - where I'm having trouble
<!DOCTYPE html>
<head>
<script type="text/javascript" src="javascript/jquery-1.10.1.js"></script>
<script>
$(document).ready(function (){
$.getJSON('/schoolweb/quizdata1.json', function(data) {
});
});
</script>
</head>
Really, anything I've tried to put in-between those curly braces - on how to read and use the data after I get it - hasn't been successful. I tried
var evaldata = eval(data)[0];
var evaldata = parseJSON(data);
and $.each statements, loops, and varieties of if statements, but nothing worked.
I was wanting to make an online quiz, that simply prints off the questions and a list of answers they can choose - but was trying to make it a separate file and use Json, Jquery, and Ajax for the question and answer data. Later, I'd like to add other Javascript to calculate the total quiz score and store it in a database, but that's for another day.
Any advice would be greatly appreciated!