原创

json对象合并的方法

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://jeecg.blog.csdn.net/article/details/5517261

求json对象合并的方法

var a ={"a":"1","b":"2"}
var b ={"c":"3","d":"4","e":"5"}

想得到结果:

var c ={"a":"1","b":"2","c":"3","d":"4","e":"5"}


怎么弄??
==================
<script>
function extend(des, src, override){
    if(src instanceof Array){
        for(var i = 0, len = src.length; i < len; i++)
             extend(des, src[i], override);
    }
    for( var i in src){
        if(override || !(i in des)){
            des[i] = src[i];
        }
    }
    return des;
}
var a ={"a":"1","b":"2"}
var b ={"c":"3","d":"4","e":"5"}
var c = extend({}, [a,b]);
alert(c.a);
</script>
文章最后发布于: 2010-04-22 19:42:00
展开阅读全文
0 个人打赏
私信求帮助

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览