정미나닷컴

[JSON] JavaScript Object Notation 본문

programming

[JSON] JavaScript Object Notation

정미나 2010. 4. 8. 16:45
반응형

: 경량의 DATA 교환 형식


- 배열 리터럴

var aNames = ["Benjamin" , "Michael" , "Scott"];

alert(aNames[0]); // Benjamin 출력
alert(aNames[1]); // Michael 출력
alert(aNames[2]); // Scott 출력

* 여러 가지 데이터 형식 저장
var aValues = ["string" , 24 , true , null ];


- 객체 리터럴

var oCar = {
  "color" : "red",
  "doors" : 4,
  "paidFor" : true
};

alert(oCar.color); // "red" 출력
alert(oCar.doors); // "4" 출력
alert(oCar.paidFor); // "true" 출력

or

alert(oCar["color"]);
alert(oCar["doors"]);
alert(oCar["paidFor"]);


- 혼합 리터럴

var aCars = [
  {
    "color" : "red",
    "doors" : 2,
    "paidFor" : true
  },
  {
    "color" : "blue",
    "doors" : 4,
    "paidFor" : true
  },
  {
    "color" : "white",
    "doors" : 2,
    "paidFor" : false
  }
];

alert(aCars[1].doors); // "4" 출력

반응형

'programming' 카테고리의 다른 글

[JSP] JSP 시간 비교  (0) 2010.04.19
[HTML4] div 공백 제거 (웹표준)  (0) 2010.04.16
[JSTL] JavaScript와 JSTL 호환  (1) 2010.04.01
application 내장객체  (0) 2010.03.22
동영상 연속 재생  (0) 2010.03.12