json入门

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>form.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">
  </head>
  <body>
  </body>
  <script language="JavaScript">
    /*
     * class Person{
     * 
     *      private String name;
     *      private String age;
     *      private String sex;
     *      省略的set和get方法
     * }
     * 
     * Person person = new Person();
     * 
     * person.name;
     * person.age;
     * 
     * json数据格式:相当于一个map集合
     *      * 是以"{}"开始和结尾的
     *      * 里面是以"key/value"键值对形式存在
     *      * "key/value"之间使用":"隔开
     *      * 多个"key/value"之间使用","隔开
     * 
     *      {
     *          key01:value01,
     *          key02:value02
     *      }
     *  
     * 
     */
    var person = {
                    "name":"zhangwuji",
                    "age":"18",
                    "sex":"male"
                  }

    alert(person.age);


  </script>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>form.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">
  </head>
  <body>
  </body>
  <script language="JavaScript">
    /*
     * class Person{
     * 
     *      private String name;
     *      private String age;
     *      private String sex;
     *      省略的set和get方法
     * }
     * 
     * Person person = new Person();
     * 
     * person.name;
     * person.age;
     * 
     * json数据格式:相当于一个数组
     *      * 是以"[]"开始和结尾的
     *      * 里面是以多个值存在
     *      * 其中,每个值是map集合存在,map集合里是以"key/value"键值对形式存在
     *      * 多个值之间用","隔开
     * 
     *      [
     *          {
     *              key01:value01,
     *              key02:value02
     *          },
     *          {
     *              key01:value01,
     *              key02:value02
     *          }
     *      ]
     *      
     *  
     * 
     */
    var person = [
                      {
                        "name":"zhangwuji",
                        "age":"18",
                        "sex":"male"
                      },
                      {
                        "name":"zhouzhiruo",
                        "age":"18",
                        "sex":"female"
                      }
                 ]


    alert(person[1].name);


  </script>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>form.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">
  </head>
  <body>
  </body>
  <script language="JavaScript">
    /*
     * class Person{
     * 
     *      private String name;
     *      private String age;
     *      private String sex;
     *      省略的set和get方法
     * }
     * 
     * Person person = new Person();
     * 
     * person.name;
     * person.age;
     * 
     * json数据格式:相当于一个数组
     *      * 是以"[]"开始和结尾的
     *      * 里面是以多个值存在
     *      * 其中,每个值是map集合存在,map集合里是以"key/value"键值对形式存在
     *      * 多个值之间用","隔开
     * 
     *      [
     *          {
     *              key01:value01,
     *              key02:value02
     *          },
     *          {
     *              key01:value01,
     *              key02:value02
     *          }
     *      ]
     *      
     *  
     * 
     */
    var person = {
                    "yttlj":
                    [
                          {
                            "name":"zhangwuji",
                            "age":"18",
                            "sex":"male"
                          },
                          {
                            "name":"zhouzhiruo",
                            "age":"18",
                            "sex":"female"
                          }
                     ]
                 }



    alert(person.yttlj[1].name);


  </script>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>form.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">
  </head>
  <body>
  </body>
  <script language="JavaScript">
    /*
     * class Person{
     * 
     *      private String name;
     *      private String age;
     *      private String sex;
     *      省略的set和get方法
     * }
     * 
     * Person person = new Person();
     * 
     * person.name;
     * person.age;
     * 
     * json数据格式:相当于一个数组
     *      * 是以"[]"开始和结尾的
     *      * 里面是以多个值存在
     *      * 其中,每个值是map集合存在,map集合里是以"key/value"键值对形式存在
     *      * 多个值之间用","隔开
     * 
     *      [
     *          {
     *              key01:value01,
     *              key02:value02
     *          },
     *          {
     *              key01:value01,
     *              key02:value02
     *          }
     *      ]
     *      
     *  
     * 
     */
    var person = [
                    {
                        "yttlj":
                        [
                              {
                                "name":"zhangwuji",
                                "age":"18",
                                "sex":"male"
                              },
                              {
                                "name":"zhouzhiruo",
                                "age":"18",
                                "sex":"female"
                              }
                         ]
                     },
                     {
                        "sdyxz":
                        [
                              {
                                "name":"guojing",
                                "age":"18",
                                "sex":"male"
                              },
                              {
                                "name":"huangrong",
                                "age":"18",
                                "sex":"female"
                              }
                         ]
                     }
                 ]




    alert(person[1].sdyxz[1].name);


  </script>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>form.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">
  </head>
  <body>
  </body>
  <script language="JavaScript">
    /*
     * class Person{
     * 
     *      private String name;
     *      private String age;
     *      private String sex;
     *      省略的set和get方法
     * }
     * 
     * Person person = new Person();
     * 
     * person.name;
     * person.age;
     * 
     * json数据格式:相当于一个数组
     *      * 是以"[]"开始和结尾的
     *      * 里面是以多个值存在
     *      * 其中,每个值是map集合存在,map集合里是以"key/value"键值对形式存在
     *      * 多个值之间用","隔开
     * 
     *      [
     *          {
     *              key01:value01,
     *              key02:value02
     *          },
     *          {
     *              key01:value01,
     *              key02:value02
     *          }
     *      ]
     *      
     *      * json数据格式可以无限嵌套下去,但是建议最多三层
     * 
     */
//  var person = {
//                  "jinyong":
//                  [
//                      {
//                          "yttlj":
//                          [
//                                {
//                                  "name":"zhangwuji",
//                                  "age":"18",
//                                  "sex":"male"
//                                },
//                                {
//                                  "name":"zhouzhiruo",
//                                  "age":"18",
//                                  "sex":"female"
//                                }
//                           ]
//                       },
//                       {
//                          "sdyxz":
//                          [
//                                {
//                                  "name":"guojing",
//                                  "age":"18",
//                                  "sex":"male"
//                                },
//                                {
//                                  "name":"huangrong",
//                                  "age":"18",
//                                  "sex":"female"
//                                }
//                           ]
//                       }
//                   ],
//                   "qingyao":
//                   [
//                      {
//                          "hzgg":
//                          [
//                                {
//                                  "name":"erkang",
//                                  "age":"18",
//                                  "sex":"male"
//                                },
//                                {
//                                  "name":"ziwei",
//                                  "age":"18",
//                                  "sex":"female"
//                                }
//                           ]
//                       },
//                       {
//                          "qssymm":
//                          [
//                                {
//                                  "name":"dufei",
//                                  "age":"18",
//                                  "sex":"male"
//                                },
//                                {
//                                  "name":"ruping",
//                                  "age":"18",
//                                  "sex":"female"
//                                }
//                           ]
//                       }
//                   ]
//               }

    var person = {
                    name:"xxx",
                    age:"xxx",
                    address:[
                        {home:"xxshixxxqu"},
                        {family:"yyshiyyqu"}
                    ]
                 }  

    //普通方法           
    function add(a,b){
        return a+b;
    }

    add(3,4);

    //使用json来定义函数
    var method = {
        add:function(a,b){
            return a+b;
        }
    }   

    method.add(3,4);         

    alert(person.qingyao[0].hzgg[1].name);


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值