json 실례 상세 설명 강좌

공식 사이트 주소:http://www.json.org/json-zh.htmljson2.js우리 다운로드 주소

<script type="text/javascript" src="json2.js"></script>
<script>
// json
var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};
// , json
var normalstring='[{persons:[{name:"jordan",sex:"m",age:"40"}, {name:"bryant",sex:"m",age:"28"}, {name:"McGrady",sex:"m",age:"27"} ]}]';
var jsontext='[{"persons":[{"name":"jordan","sex":"m","age":"40"}, {"name":"bryant","sex":"m","age":"28"}, {"name":"McGrady","sex":"m","age":"27"} ]}]';

// eval json ,
var myE = eval(normalstring);
document.writeln(myE+'<br><br>');
// json
var text = JSON.stringify(myE);
// json
document.writeln(' json :'+text+'<br><br> json '+jsontext+'<br><br> '+normalstring+'<br><br>');

// JSON 。JSON JSON , json parse json
var myData = JSON.parse(jsontext);

document.writeln(myData+'<br><br>');

// json

// json

var jsonObj2={persons:[{name:"jordan",sex:"m",age:"40"}, {name:"bryant",sex:"m",age:"28"}, {name:"McGrady",sex:"m",age:"27"} ]};

var persons=jsonObj2.persons;
var str="";

var person={name:"yaoMing",sex:"m",age:"26"};
// json ,
//jsonObj2.persons.push(person);//
//jsonObj2.persons.pop();//
//jsonObj2.persons.shift();//
jsonObj2.persons.unshift(person);// Javascript JSON ! splice( ) crud ! //
//jsonObj2.persons.splice(0,2);// ,
//
var self={name:"tom",sex:"m",age:"24"};
var brother={name:"Mike",sex:"m",age:"29"};
jsonObj2.persons.splice(1,0,self,brother,self);// , ,
//
//jsonObj2.persons.splice(0,1,self,brother);// , ,

for(var i=0;i<persons.length;i++){ var cur_person=persons[i]; str+=cur_person.name+"'sex is "+cur_person.sex+" and age is "+cur_person.age+"<br><br>"; }
document.writeln(str);
// json
var myjsonobj = JSON.stringify(jsonObj2);
document.writeln(myjsonobj);
</script>

좋은 웹페이지 즐겨찾기