HTML vs JSON

๋ชจ๋ฐ”์ผ ์›น ํŽ˜์ด์ง€๋ฅผ ๋ณด๋‹ค๋ณด๋ฉด API context-type์„ application/jsonํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๋Š” ๊ณณ๋„ ์žˆ๊ณ , text/html ํ˜•ํƒœ๋กœ ๋ฐ›๋Š” ๊ณณ๋„ ์žˆ์—ˆ๋‹ค. ๋‘ ๊ฐœ์˜ ์ฐจ์ด์ ์ด ๊ถ๊ธˆํ•ด์ ธ ํ•ด๋‹น ๋ถ€๋ถ„์„ ์ฐพ์•„๋ณด์•˜๋‹ค.

๋ณดํ†ต ํ•„์š”ํ•œ ๊ฒƒ์ด ๋ฐ์ดํ„ฐ์ด๋ฉฐ, ์ถ”๊ฐ€์ ์ธ ๊ณ„์‚ฐ์ด ํ•„์š”ํ• ๋•Œ application/json ํƒ€์ž…์„ ์‚ฌ์šฉํ•˜๊ณ , ์–ด๋–ค ๊ณ„์‚ฐ๋„ ํ•„์š”ํ•˜์ง€ ์•Š์œผ๋ฉฐ, ๋ณด์—ฌ์ฃผ๋Š” ์šฉ๋„๋กœ ์‚ฌ์šฉํ• ๋–„๋Š” HTML์„ ์‚ฌ์šฉํ•œ๋‹ค.

  • text/html์€ parsingํ•˜๊ธฐ ์ „๊นŒ์ง€ ์ž˜๋ชป๋œ ๋ถ€๋ถ„์„ ์ฐพ๊ธฐ ํž˜๋“ค๋ฉฐ, application/json์€ ์ž˜๋ชป๋œ ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ์‰ฝ๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.(๋””๋ฒ„๊น…์ด ์šฉ์ด)

  • application/json์€ ์ฆ‰์‹œ js object๋กœ ๋ณ€ํ™˜๋˜์–ด obj.firstnode.childnode๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

  • applicaton/json์€ callback์ด ๊ฐ€๋Šฅํ•˜๋‚˜, text/html์€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.

  • applcation/json๋ณด๋‹ค text/html์ด ์กฐ๊ธˆ ๋” ๋น ๋ฅด๋‹ค.

  • HTML์€ ํด๋ผ์ด์–ธํŠธ๋‹จ์—์„œ ์ถ”๊ฐ€์ ์œผ๋กœ ๊ณ„์‚ฐ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋Š” ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋œ๋‹ค.

  • JSON์„ ํŽ˜์ด์ง€์˜ DOM tree์— ํฌํ•จํ•˜๋Š” ๊ฒƒ์ด ์ „๋ถ€๋ผ๋ฉด ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

์ฐธ๊ณ 

Last updated