Struts2 JSON

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式
 (本质是一种数据传输格式)

 定义json对象

var json={"firstName":"hehe","secondName":"he","thirdName":"heh"};
     
     
     $.each(json,function(i,dom){
        alert(dom);
     });

效果:

 

 

 定义json数组

 

 var json=
     {
    "people":[
        {"firstName":"孙悟空","lastName":"大闹天宫","email":"aaaa"},
        {"firstName":"美猴王","lastName":"花果山山大王","email":"bbbb"},
        {"firstName":"大圣","lastName":"天上各位尊神尊称他","email":"cccc"},
          {"firstName":"弼马温","lastName":"人生第一份工作","email":"DDDD"}
    ]
   };
   
   $.each(json.people,function(i,dom){
        alert(d

效果:

 

 

 var json={
    "programmers": [{
        "firstName": "Brett",
        "lastName": "McLaughlin",
        "email": "aaaa"
    }, {
        "firstName": "Jason",
        "lastName": "Hunter",
        "email": "bbbb"
    }, {
        "firstName": "Elliotte",
        "lastName": "Harold",
        "email": "cccc"
    }],
    "authors": [{
        "firstName": "Isaac",
        "lastName": "Asimov",
        "genre": "sciencefiction"
    }, {
        "firstName": "Tad",
        "lastName": "Williams",
        "genre": "fantasy"
    }, {
        "firstName": "Frank",
        "lastName": "Peretti",
        "genre": "christianfiction"
    }],
    "musicians": [{
        "firstName": "Eric",
        "lastName": "Clapton",
        "instrument": "guitar"
    }, {
        "firstName": "Sergei",
        "lastName": "Rachmaninoff",
        "instrument": "piano"
    }]
};
     $.each(json.programmers,function(i,dom){
        alert(dom.firstName+"\n"+dom.lastName+"\n"+dom.instrument);
   });

  其效果:

其它都一样,就不一一截图了

 

posted @ 2016-10-14 14:56  Monodrama  阅读(220)  评论(0编辑  收藏  举报