js操作json添加元素和数据的方法

时间:2014-05-09 00:16:33   收藏:0   阅读:654
bubuko.com,布布扣
function addServerUrlToJson() {
    var json_tem = [{"name":"a","value":1}];
    
    var arr  =
     {
         "name" : "aaa",
         "value" : "bbb"
     };
     json_tem.push(arr);
     document.write(JSON.stringify(json_tem));
} 
bubuko.com,布布扣

结果:[{"name":"a","value":1},{"name":"aaa","value":"bbb"}]

function addServerUrlToJson() {
    var url_path_down = "http://10.10.3.221/";
    var json_tem = {"name":"a","value":1};
    json_tem["url_path_down"] = url_path_down;
    document.write(JSON.stringify(json_tem));
} 

结果:{"name":"a","value":1,"url_path_down":"http://10.10.3.221/"}

js操作json添加元素和数据的方法,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!