zoukankan      html  css  js  c++  java
  • json格式示例

    案例一:

      {key:value,key:value}

    class Person{
             String firstname = "张";
             String lastname = "三丰";
             Integer age = 100;
          }
          
          Person p = new Person();
          System.out.println(p.firstname);

    转JS:

    var person = {"firstname":"张","lastname":"三丰","age":100};
         
         //取出lastname
         alert(person.lastname);
         //取出age
         alert(person.age);

    案例二:
           [{key:value,key:value},{key:value,key:value}]

        Person[] persons = new Person[1];
        Person p0 = new Person("张","三丰",100);
        Person p1 = new Person("李","四",25);
        persons[0] = p0;
        persons[1] = p1;
        System.out.println(persons[0].age);
        System.out.println(persons[1].firstname);

    转JS:

    var persons = [
                    {"firstname":"张","lastname":"三丰","age":100},
                     {"firstname":"李","lastname":"四","age":25}
                   ];
         //取出fistname=李
         alert(persons[1].firstname);
         //取出age=100
         alert(persons[0].age);

    案例三:
       {

          "param":[{key:value,key:value},{key:value,key:value}]

       }

    var json = {
                     "baobao":[
                               {"name":"yg",age:22,"addr":"南通"},
                               {"name":"gy",age:22,"addr":"徐州"}
                               ]
                 };
         //取name = gy
         alert(json.baobao[1].name);
         //取addr = 南通 
         alert(json.baobao[0].addr);
        

    案例四:
          {
            "param1":[{key:value,key:value},{key:value,key:value}],
            "param2":[{key:value,key:value},{key:value,key:value}],
            "param3":[{key:value,key:value},{key:value,key:value}]
          }

    var json = {
                     "baobao":[
                               {"name":"yg",age:22,"addr":"南通"},
                               {"name":"gy",age:22,"addr":"徐州"}
                               ],
                     "haohao":[{"name":"xh",age:23,"addr":"南京"},
                               {"name":"aj",age:22,"addr":"淮阴"}    
                               ]
                 };
    //取name = gy
    alert(json.baobao[1].name);
    //取addr = 淮阴 
    alert(json.haohao[1].addr);

    案例五:
          {
            "param1":"value1",
            "param2":{},
            "param3":[{key:value,key:value},{key:value,key:value}]
          }

    var json = {
                     "key1":"value1",
                     "key2":{"firstname":"张","lastname":"三丰","age":100},
                    "key3":[
                           {"name":"yg",age:22,"addr":"南通"},
                            {"name":"gy",age:22,"addr":"徐州"}                  
                           ]         
         };
         alert(json.key2.firstname);
         alert(json.key3[1].age);
  • 相关阅读:
    SpringBoot+ElementUI实现通用文件下载请求(全流程图文详细教程)
    Java中将String格式的标准时间字符串转换为Date格式的方法
    ElementUI中el-upload传递额外参数为date类型时后台SpringBoot接收不到
    模式、框架、架构和平台的区别
    架构、框架、模式和平台
    “模式”与“方式”的区别
    JAVA发送HTTP请求方式
    http status状态码,readyState状态码
    区分网络请求时http和ajax请求
    HTTP请求方式中8种请求方法
  • 原文地址:https://www.cnblogs.com/yg1024/p/8340743.html
Copyright © 2011-2022 走看看