I'm not able to get the value from a json-object in jquery. It throws the error message("Uncaught SyntaxError: Unexpected token H") in developer tool.
How can I get the value from my JSON-Object?
Please let me know.
The PHP-Code: (unedited)
[
{
"qus_type": "choice",
"qus_text": "Which one is if statement?",
"correct_answer": "<?php$t=date("H");if ($t<"20") { echo "Haveagoodday!";}?>",
"choice1": "<?php$t=date("H");if ($t<"20") { echo "Haveagoodday!";} else { echo "Haveagoodnight!";}?>",
"choice2": "<?php$t=date("H");if ($t<"20") { echo "Haveagoodday!";}?>",
"choice3": "<?php$t=date("H");if ($t<"10") { echo "Haveagoodmorning!";} elseif ($t<"20") { echo "Haveagoodday!";} else { echo "Haveagoodnight!";}?>",
"choice4": "",
"choice5": ""
}
]
The Javascript / jQuery-part:
jsonObj = jQuery.parseJSON(ques_json);
window.jQuery(jsonObj).each(function(index, item) {
console.log(item.qus_type);
console.log(item.qus_text);
console.log(item.correct_answer);
console.log(item.choice1);
console.log(item.choice2);
console.log(item.choice3);
console.log(item.choice4);
console.log(item.choice5);
})