码迷,mamicode.com
首页 > Web开发 > 详细

JSon数据类型&使用基础

时间:2018-09-07 01:03:31      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:color   on()   user   tle   bsp   null   json   数据   span   

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>Insert title here</title>
 6     <script type="text/javascript">
 7         function jSon() {
 8             var jSonObject = {"name":"xiaostudy","age":"23"};
 9             alert("jSonObject.name=" + jSonObject.name);
10             alert("jSonObject.age=" + jSonObject.age);
11         }
12         
13         function jSon2() {
14             var User = {"name":"xiaostudy","age":"23"};
15             var User2 = {"name":"xiaostudy2","age":"24"};
16             var User3 = {"name":"xiaostudy3","age":25};//Number类型
17             var User4 = {"name":"xiaostudy4", age:26};//String类型
18             var User5 = {"name":"xiaostudy5", age:27,ft:true};//Boolean类型
19             var User6 = {"name":"xiaostudy6", age:28,ft:true,array:[1,2,3]};//Array类型
20             var User7 = {"name":"xiaostudy6", age:28,ft:true,array:[1,2,3], null:null};//null类型
21             //var jSonObject = [{"name":"xiaostudy","age":"23"}, {"name":"xiaostudy2","age":"24"}];
22             var jSonObject = [User, User2, User3, User4, User5, User6, User7];//Object类型
23             
24             alert("jSonObject[0].name=" + jSonObject[0].name);
25             alert("jSonObject[1].age=" + jSonObject[1].age);
26             alert("jSonObject[2].age=" + jSonObject[2].age);
27             alert("jSonObject[3].age=" + jSonObject[3].age);
28             alert("jSonObject[4].ft=" + jSonObject[4].ft);
29             alert("jSonObject[5].array[1]=" + jSonObject[5].array[1]);
30             alert("jSonObject[6].null=" + jSonObject[6].null);
31         }
32         
33     </script>
34 </head>
35 <body>
36     <p>
37         var User = {"name":"xiaostudy","age":"23"};<br/>
38         var User2 = {"name":"xiaostudy2","age":"24"};<br/>
39         var User3 = {"name":"xiaostudy3","age":25};//Number类型<br/>
40         var User4 = {"name":"xiaostudy4", age:26};//String类型<br/>
41         var User5 = {"name":"xiaostudy5", age:27,ft:true};//Boolean类型<br/>
42         var User6 = {"name":"xiaostudy6", age:28,ft:true,array:[1,2,3]};//Array类型<br/>
43         var User7 = {"name":"xiaostudy6", age:28,ft:true,array:[1,2,3], null:null};//null类型<br/><br/>
44         
45         var jSonObject = [User, User2, User3, User4, User5, User6, User7];//Object类型<br/>
46     </p>
47     <input type="button" value="jSon的name" onclick="jSon()"/><br/>
48     <input type="button" value="jSon" onclick="jSon2()"/><br/>
49 </body>
50 </html>

 

JSon数据类型&使用基础

标签:color   on()   user   tle   bsp   null   json   数据   span   

原文地址:https://www.cnblogs.com/xiaostudy/p/9601995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!