๐ ์๋ฐ ์๋ฒ ํ์ด์ง JSP/๐ธ ์ ์ด์จ XML\JSON
3๏ธโฃ ์ ์ด์จ JSON - ๋๊ตฌํ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
Meteora_
2021. 3. 9. 20:35
728x90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p id="demo"></p>
<script type="text/javascript">
let json = {
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
}
},
"maths": {
"q1": {
"question": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"q2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
};
function jsonTest() {
document.getElementById("demo").innerHTML
// = json.quiz["sport"].q1.question;
// = json.quiz["sport"].q1.options[2];
= json.quiz["maths"].q2.question;
}
jsonTest();
</script>
</body>
</html>
NBAjson.json
{
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
}
},
"maths": {
"q1": {
"question": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"q2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
}