json对象合并的方法
Posted skiwndhw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json对象合并的方法相关的知识,希望对你有一定的参考价值。
求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"}
怎么弄??
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>
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>
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
以上是关于json对象合并的方法的主要内容,如果未能解决你的问题,请参考以下文章