:
<script type="text/javascript" src="scripts/json/json2.js"></script>
<script type="text/javascript" src="scripts/json/jsonmessage.js"></script>
javascriptJSON
Js
:
//
var JSONObject = {}
//
var JSONObject = new Object()
//
var JSONObject = {
"name":"kevin",
"age":23
}
java(.)
:
var JSONObject = {
"name":"kevin",
"age":24,
};
alert("JSONObject.name:"+JSONObject.name);
alert("JSONObject.age:"+JSONObject.age);
javascriptJSON
Student,УStudent
:
var student = {
//Class
"Class":[
{
"name":"kevin",
"className":"java",
"age":23
},
{
"name":"yang",
"className":"java",
"age":24
}
],
//
"Score":[
{
"name":"shower",
"score":100
},
{
"name":"zheng",
"score":100
}
]
}
var i=0;
for(i=0;i<student.Class.length;i++){
alert("student.Class["+i+"].name===>"+student.Class[i].name);
alert("student.Class["+i+"].className===>"+student.Class[i].className);
alert("student.Class["+i+"].age===>"+student.Class[i].age);
}
for(i=0;i<student.Score.length;i++){
alert("student.Score["+i+"].name===>"+student.Score[i].name);
alert("student.Score["+i+"].score===>"+student.Score[i].score);
}
JSONjavascriptд
:
//create a Student Object
var Student = {
"Math":[{
"name":"kevin",
"mark":70,
"age":23
},{
"name":"smart",
"mark":40,
"age":25
}
],
"Science":[{
"name":"kevin2",
"mark":70,
"age":23
},{
"name":"smart2",
"mark":40,
"age":25
}
]
}
//print array value
var i = 0;
var array = new Array();
for(i=0;i<Student.Math.length;i++){
array.push(Student.Math[i].name);
array.push(Student.Math[i].mark);
array.push(Student.Math[i].age);
}
for(i=0;i<Student.Science.length;i++){
array.push(Student.Science[i].name);
array.push(Student.Science[i].mark);
array.push(Student.Science[i].age);
}
alert("array==>"+array);
//This method produce a JSON text from a JavaScript value.
//JavaScriptJSON
alert("array.toJSONString()==>"+array.toJSONString());
alert("String.parseJSON==>"+array.toJSONString().parseJSON());
var data2 = array.toJSONString().parseJSON();
if(data2 instanceof Array){
alert("Array");
}
:
//
//var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
// escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
//
var cx = new RegExp('/[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g'),
escapable = new RegExp('/[\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g'),
(Tag):