IT
[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" 출력