我到处找了一个方法来做这件事,但我只能找到零碎的东西,一直被卡住。
我想添加两组json,保留所有属性,但如果存在重复的owner
值,则添加total
值。在
json1 = [{"total":101,"owner":"User1","type":8,"team":"Team1"},
{"total":44,"owner":"User2","type":8,"team":"Team1"},
{"total":22,"owner":"User3","type":8,"team":"Team2"}]
json2 = [{"total":12,"owner":"User1","type":8,"team":"Team1"},
{"total":33,"owner":"User3","type":8,"team":"Team2"},
{"total":18,"owner":"User4","type":8,"team":"Team1"}]
我想让输出看起来像这样
^{pr2}$或者,如果我有一个单独的json集,并且希望找到重复的owner
并合并{finaljson
。在
mergedjson = json1.extend(json2)
变成{
谢谢!在
试试这个,虽然这不是最好的解决办法。在
DEMO
相关问题 更多 >
编程相关推荐