<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>JSON 데이터 읽어오기</h2>
<!-- json 데이터 샘플 -->
<a href="https://jsonplaceholder.typicode.com/" target="_blank">json 데이터 샘플</a><br><br>
<input type="file" id="loader">
<script>
const obj1=document.getElementById("loader");
obj1.addEventListener("change", loadFile, false);
function loadFile(e){
const file=e.target.files[0];
if(file){
const reader=new FileReader();
reader.onload=function(e){
console.log("reader onload -->>")
//console.dir(e.target.result);
const json =JSON.parse(e.target.result);
console.dir(json);
console.log(json[0].title);
}
reader.readAsText(file);
}
}
</script>
</body>
</html>
javascript
댓글 ( 4)
댓글 남기기