<script type="text/javascript" src=""></script>
<script>
//Directly declare the json data structure
var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};
//Declare strings, you can compare the difference between json text and our normal text
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"} ]}]';
//Calling the eval function to convert it into a json object,
var myE = eval(normalstring);
(myE '<br><br>');
//Convert json object to string
var text = (myE);
//Compare the difference between converted json text and declared text
('Converted json text:' text '<br><br>Declared json format text' jsontext '<br><br>Declared normal format text' normalstring '<br><br>');
//It is better to use JSON parsing when security is more important. JSON parsing will only recognize JSON text and it is safer. The following calls json's parse function to convert text data to generate json data structure
var myData = (jsontext);
(myData '<br><br>');
//The following is the addition, deletion, search and modification operation of json objects
//Declare json object
var jsonObj2={persons:[{name:"jordan",sex:"m",age:"40"}, {name:"bryant",sex:"m",age:"28"}, {name:"McGrady",sex:"m",age:"27"} ]};
var persons=;
var str="";
var person={name:"yaoMing",sex:"m",age:"26"};
//The following is the operation of the json object. Remove the comments to view the operation results
//(person);//A record is added to the last array
//();//Delete the last item
//();//Delete the first item
(person);//A record is added at the beginning of the array. As long as the method suitable for Javascript can be used in the array of JSON objects! So there is another method to splice( ) for crud operation! //delete
//(0,2);//The number of deletes is deleted at the beginning position
//Replace without deletion
var self={name:"tom",sex:"m",age:"24"};
var brother={name:"Mike",sex:"m",age:"29"};
(1,0,self,brother,self);//Start position, delete number, insert object
//Replace and delete
//(0,1,self,brother);//Start position, delete number, insert object
for(var i=0;i<;i ){ var cur_person=persons[i]; str =cur_person.name "'sex is " cur_person.sex " and age is " cur_person.age "<br><br>"; }
(str);
//Convert to json text
var myjsonobj = (jsonObj2);
(myjsonobj);
</script>