JSON

JSON JSON in JavaScript

字号+ 作者:H5之家 来源:H5之家 2015-11-10 09:23 我要评论( )

javascript

:


<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):

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • php CI 实战教程:[5]用curl获取json并解析

    php CI 实战教程:[5]用curl获取json并解析

    2016-02-26 17:00

  •  JSON入门级学习总结-JSON数据结构

    JSON入门级学习总结-JSON数据结构

    2016-02-25 11:05

  • Android解析Json速度最快的库:json

    Android解析Json速度最快的库:json

    2016-02-13 18:00

  • JavaScript转换与解析JSON方法实例详解第1/2页

    JavaScript转换与解析JSON方法实例详解第1/2页

    2016-02-10 21:25

网友点评
a