자바스크립트 JSON
●자바스크립트 JSON(JavaScript Object Notation)
- JSON은 원래 자바스크립트 데이터 객체이다.
- JSON이란 데이터를 표현함에 있어 xml보다 더욱 단순하고 객체 표현방식이 기존의 개발자들에 익숙한 {객체표기법}을 따르므로 데이터 처리가 쉽다.
●예제
- text.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> <script> var rabbit = { name:"토끼", age:"22", like:["당근","풀"], isBool:true, father:{ name:"토끼아빠", age:"50" }, friend:[ { name:"토끼친구1", age:"22" }, { name:"토끼친구2", age:"22" } ] } document.write("이름:"+rabbit.name+"<br>"); document.write("나이:"+rabbit.age+"<br>"); document.write("논리:"+rabbit.isBool+"<br>"); document.write("like1:"+rabbit.like[0]+"<br>"); document.write("like2:"+rabbit.like[1]+"<br>"); document.write("아빠이름:"+rabbit.father.name+"<br>"); document.write("아빠나이:"+rabbit.father.age+"<br>"); document.write("친구1:"+rabbit.friend[0].name+"<br>"); document.write("친구2:"+rabbit.friend[1].name+"<br>"); </script> </head> <body> </body> </html> |