可能重复:
添加两个 json 对象并排序
我有两个 json 对象
[
{"name": "Graduation"},
{"name": "Post Graduation"}
]
另一个也一样
[
{"name": "first sem"},
{"name": "second sem"},
{"name": "third sem"}
]
如何将两个 json 对象合二为一,例如
[
{"name": "Graduation"},
{"name": "Post Graduation"},
{"name": "first sem"},
{"name": "second sem"},
{"name": "third sem"}
]
我试过了
_this.model = new qualification();
_this.model1 = new sems();
jsondata = _this.model.toJSON();
jsonData = _.extend(_this.model1.toJSON(),jsonData)
通过覆盖键获取json
even I tried
var result = _.union([jsonData1],[jsonData2]);
console.log(JSON.stringify(result));
并且使用 concat 也将输出打印为
[{"0":{"name":"first sem"},"1":{"name":"second sem"},"2":{"name":"third sem"}},{"0":{"name":"Graduation"},"1":{"name":"Post Graduation"}}],