日期:2014-05-16  浏览次数:20360 次

JSON数据格式以及与后台交互数据转换实例
/*

作者:烟大阳仔

时间:20131013

介绍:主要了解一下json的格式,看看数据是怎么存储的
*/

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript"> /*  class person  {   Integer id;   String name;  }  Person p=new Person(); */  //jason格式标识一个对象  var people={"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"};  //alert(people.firstName);  //json标识多个人  var people2=  [   {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},   {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},   {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"}  ]  //alert(people2[1].firstName);  //别名:  var people3={"person":  [   {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},   {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},   {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"}  ]  }  //alert(people3.person[1].firstName);  var people3={  "person1":   [    {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},    {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},    {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"}   ],  "person2":   [    {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},    {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},    {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"}   ],  "person3":   [    {"firstName":"wy","lastName":"hao","email":"1221@qq.com"},    {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"},    {"firstName":"zhangsan","lastName":"hao","email":"1221@qq.com"}   ]  }  //alert(people3.person3[0].firstName);   </script> </head> <body>

</body> </html>

------------------------------------------------------------------------- /* 作者:烟大阳仔 时间:20131013 介绍:主要了学习一下json与后台交互的时候数据的转换 */

<!DOCTYPE html> <html>   <head>     <title>json2.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