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"].options[2];
=json.quiz["maths"].q2.question;
//quiz는 두개기때문에 배열로 잡혔다
}
jsonTest();
</script>
</body>
</html>
{
"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"
}
}
}
}
728x90
'HTML' 카테고리의 다른 글
JSON <자신이 읽은 책 5권을 JSON파일로 제작후 테이블로 시각화 하기> (0) | 2021.03.09 |
---|---|
XML / <자신이 읽은 책 5권을 XML파일로 제작후 테이블로 시각화 하기> (0) | 2021.03.09 |
39일차//JSON// JSON 구조 문법 + 실습 (0) | 2021.03.09 |
39일차//XML// 🧶3. xml 파일을 생성해 데이터작성 후 불러오기 (0) | 2021.03.09 |
39일차//XML// 🧶2. parser.parseFromString 문자열 파싱 (0) | 2021.03.09 |