I'm trying to convert the following json:
{
"questions": [
{
"question#1": "How much is 3+1",
"correct answer": 1,
"answers": {
"ans#1": "5",
"ans#2": "4",
"ans#3": "3"
}
},
{
"question#5": "How much is 2+4",
"correct answer": 0,
"answers": {
"ans#1": "6",
"ans#2": "4",
"ans#3": "7",
"ans#4": "5"
}
}
]
}
by using the following code in Jquery:
$(document).ready(function(){
$.getJSON("data.json", function(json) {
console.log(json); // this will show the info it in firebug console
var sarit = Object.keys(json); // "a"
});
/*var update = document.getElementById("content");
update.innerHTML("test");*/
document.getElementById("content").innerHTML = JSON.stringify(sarit);
});
I got an error-Uncaught ReferenceError: sarit is not defined
How can I get the answers' value of each question, and use it in the html file, aka content