๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŒ  ์ž๋ฐ” ์„œ๋ฒ„ ํŽ˜์ด์ง€ JSP/๐Ÿ›ธ ์ œ์ด์Šจ XML\JSON

3๏ธโƒฃ ์ œ์ด์Šจ JSON - ๋†๊ตฌํŒ€ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ

by Meteora_ 2021. 3. 9.
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"
            }
        }
    }
}

๋Œ“๊ธ€