자바스크립트

 

<!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>

 

 

about author

PHRASE

Level 60  라이트

인생은 한 권의 책과 같다. 어리석은 사람은 대충 책장을 넘기지만, 현명한 사람은 공들여서 읽는다. 그들은 단 한 번 밖에 읽지 못하는 것을 알기 때문이다. -장 파울-

댓글 ( 4)

댓글 남기기

작성

자바스크립트 목록    more