码迷,mamicode.com
首页 > 编程语言 > 详细

js json 数组 添加

时间:2015-07-09 13:07:04      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

数据语法:

{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}

JS添加:

            var json = {"employees": []};
            var jsonitem = { "firstName":"Peter" , "lastName":"Jones" };
            var jsonitem2 = { "firstName":"John" , "lastName":"Doe" };
            var jsonitem3 = { "firstName":"Anna" , "lastName":"Smith" };
            json.employees.push(jsonitem);
            json.employees.push(jsonitem2);
            json.employees.push(jsonitem3);
            alert(json.employees[2].firstName);

 

js json 数组 添加

标签:

原文地址:http://www.cnblogs.com/wangliuwei/p/4632778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!