JSON基本格式

<!DOCTYPE html>
<html>
  <head>
    <title>01_json.html</title>
	
    
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
  <script type="text/javascript">
  	/*
  	 * 构建符合"key/value"格式的JSON数据格式
  	 * 	* 是以"{}"开始和结束的
  	 * 	* 数据格式是以"key/value"格式存在
  	 * 	* key/value之间使用":"隔开
  	 * 	* 多个数据之间使用","隔开
  	 * 	* 访问JSON格式的value值:json格式名称.key
  	 */
	
	var person = {
		name : "zhangwuji",
		age : 18,
		sex : "male"
	}
	
	alert(person.name);
	
	
  </script>
</html>
<!DOCTYPE html>
<html>
  <head>
    <title>02_json.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
  <script type="text/javascript">
  	/*
  	 * 构建符合数组格式的JSON数据格式:javascript里的数组完全一致
  	 */
	
	var person = ["person1","person2","person3"];
	
	alert(person[0]);
	
  </script>
</html>
<!DOCTYPE html>
<html>
  <head>
    <title>03_json.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
  <script type="text/javascript">
  	var person = [
		{
			name : "zhangwuji",
			age : 18,
			sex : "male"
		},
		{
			name : "zhouzhiruo",
			age : 18,
			sex : "female"
		}
	];
	
	alert(person[0].name);
	
  </script>
</html>
<!DOCTYPE html>
<html>
  <head>
    <title>04_json.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
  <script type="text/javascript">
  	var person = {
		"yttlj":
		[
			{
				name : "zhangwuji",
				age : 18,
				sex : "male"
			},
			{
				name : "zhouzhiruo",
				age : 18,
				sex : "female"
			}
		],
		"tlbb":
		[
			{
				name : "xuzhu",
				age : 18,
				sex : "male"
			},
			{
				name : "menggu",
				age : 18,
				sex : "female"
			}
		]
	}
	
	alert(person.tlbb[0].name);
	
  </script>
</html>
<!DOCTYPE html>
<html>
  <head>
    <title>05_json.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
  <script type="text/javascript">
//  	var person = {
//		"wuxia":
//		{
//			"yttlj":
//			[
//				{
//					name : "zhangwuji",
//					age : 18,
//					sex : "male"
//				},
//				{
//					name : "zhouzhiruo",
//					age : 18,
//					sex : "female"
//				}
//			],
//			"tlbb":
//			[
//				{
//					name : "xuzhu",
//					age : 18,
//					sex : "male"
//				},
//				{
//					name : "menggu",
//					age : 18,
//					sex : "female"
//				}
//			]
//		},
//		"yanqing":
//		{
//			"hzgg":
//			[
//				{
//					name : "wuage",
//					age : 18,
//					sex : "male"
//				},
//				{
//					name : "xiaoyanzi",
//					age : 18,
//					sex : "female"
//				}
//			],
//			"qssymm":
//			[
//				{
//					name : "heshuhuan",
//					age : 18,
//					sex : "male"
//				},
//				{
//					name : "luyiping",
//					age : 18,
//					sex : "female"
//				}
//			]
//		}
//	}
	
//	var person = {
//		name : "xxx",
//		age : 18,
//		sex : "male",
//		address : {
//			"home":"xxshixxqu",
//			"family":"yyshiyyqu"
//		}
//	};
	
	//将javascript代码实现块状结构
	var method = {
		add : function(a,b){
			return a + b;
		}
	}
	
	alert(method.add(1,2));			//output	3
	
	//alert(person.yanqing.hzgg[0].name);
	
  </script>
</html>





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值