HTTP method & JSON

nathan·2021년 8월 14일
0

API

목록 보기
2/4

1. HTTP

a. HTTP의 정의

Hyper Text Transfer Protocol

  • client는 server에 HTTP REQUEST를 보낸다.
  • server는 해당 요청을 받아 HTTP RESPONSE를 client에게 보낸다.

b. HTTP method란?

c. HTTP 응답 요청 코드

2. JSON

a. JSON의 정의

JavaScript Object Notation

  • 매우 유사함을 알 수 있다.

b. JSON 문법

  • Name-value 형식의 쌍 {"key":"value"}
  • 순서화된 리스트 형식 [value1, value2]

c. JSON 데이터 자바스크립트 데이터로 바꾸기

<!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코드 JS코드로 바꾸기</h2>
    <script>
      const json = `{
        "name" : "nathan29849",
        "age" : "99",
        "friends" : {"#":2,
                    "classmate": "YANG",
                    "neighborhood": "Lee"},
        "residence" : "Hwaseong-si",
        "hobby" : ["Playing the piano", "Drawing picture"]
        
    }`;
      const obj = JSON.parse(json);
      document.write(obj.name + "<br>");
      document.write(obj.age + "<br>");
      document.write(obj.friends + "<br>");
      document.write(obj.friends.classmate + "<br>");
      document.write(obj.residence + "<br>");
      document.write(obj.hobby + "<br>");
    </script>
  </body>
</html>

결과

profile
나는 날마다 모든 면에서 점점 더 나아지고 있다.

0개의 댓글