심심해서 검색하다가 롤 캐릭터와 캐릭터의 정보를 가지고 있는 json형태의 파일을 찾았다.
여기서 json이란? -> 요기
JSON - 위키백과, 우리 모두의 백과사전
위키백과, 우리 모두의 백과사전. JSON(제이슨[1], JavaScript Object Notation)은 속성-값 쌍( attribute–value pairs and array data types (or any other serializable value)) 또는 "키-값 쌍"으로 이루어진 데이터 오브젝트를
ko.wikipedia.org
내가 찾은 파일이다.
http://ddragon.leagueoflegends.com/cdn/10.14.1/data/en_US/ champion.json
또 여기에 들어가면 다양한 정보들이 있다.
https://developer.riotgames.com/docs/lol#data-dragon_champions
Riot Developer Portal
League of Legends Overview This set of documentation will help you gain a better understanding of how to use the APIs and developer resources related to League of Legends. It is designed to help you begin developing your own tools and products for the Leag
developer.riotgames.com
쨋든, json 파일을 javascript로 읽어와 보자!
<button onclick="click()">click</button>
이러한 버튼태그를 생성!
function click(){
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET','http://ddragon.leagueoflegends.com/cdn/10.14.1/data/en_US/champion.json');
}
XMLHttpRequest를 생성하여 ourRequest 인스턴스를 생성한다.
또 json 파일을 get 방식으로 open()함수 사용!
ourRequest.send();
send()함수를 사용하여 요청하고,
ourRequest.onload = function(){
console.log(ourRequest.responseText);
}
를 추가한다.
그리고 클릭을 해보면!

json 파일을 읽어 온 것을 알 수 있다.
'코딩 > JavaScript' 카테고리의 다른 글
React + Electron 배포 시 빈 화면 출력, HashRouter 설정, Router설정 (0) | 2022.05.03 |
---|