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 xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if(xhttp.readyState == 4 && xhttp.status == 200){
jsonFunc(xhttp.responseText);
}
}
xhttp.open("GET", "data.json", true);
xhttp.send();
function jsonFunc( respTxt ) {
// alert(respTxt);
let json = JSON.parse(respTxt);
// alert(json);
// alert(json.length);
let txt = "";
/*
let array = [11, 22, 33];
for(i in array){
console.log(array[i]);
}
*/
/*
for(i = 0;i < json.length; i++){
for(key in json[i]){
txt += key + ":" + json[i][key];
}
txt += "<br>";
}
*/
for(i = 0;i < json.length; i++){
txt += json[i].name + " " +
json[i].age + " " +
json[i].address + " " +
json[i].height + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
Json ํ์ผ-> data.json
[
{
"name":"์ ์๋",
"age":23,
"address":"์์ธ์",
"height":181.1
},
{
"name":"์ฌ์ฒญ์ด",
"age":14,
"address":"๊ฐ์์",
"height":165.3
},
{
"name":"ํฅ๋จ์ด",
"age":16,
"address":"๋จ์์",
"height":157.9
},
{
"name":"์ด๋ชฝ๋ฃก",
"age":18,
"address":"๊ณต์ฃผ์",
"height":173.7
}
]
'๐ ์๋ฐ ์๋ฒ ํ์ด์ง JSP > ๐ธ ์ ์ด์จ XML\JSON' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
4๏ธโฃ ์ ์ด์จ JSON - ์๊ธฐ๊ฐ ์ข์ํ๋์ฑ 5๊ฐ์ง ํ ์ด๋ธ ์๊ฐํ XML+ (0) | 2021.03.09 |
---|---|
3๏ธโฃ ์ ์ด์จ JSON - ๋๊ตฌํ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ (0) | 2021.03.09 |
1๏ธโฃ ์ ์ด์จ JSON - ๊ธฐ๋ณธ 1 (0) | 2021.03.09 |
4๏ธโฃ XML - ์์ฉ (0) | 2021.03.09 |
3๏ธโฃ XML - ๋ฌธ์์ด ๋์ ๊ณผ ์ค์ XMLํ (0) | 2021.03.09 |
๋๊ธ