如何在Java上对重复数据的数组值求和

时间:2019-02-26 17:07:56

标签: java android arraylist

我有来自arraylist的JSON数据

原样:

[{"CategoryID":"2","Discontinued":"0","ProductID":"3","ProductName":"Aniseed Syrup","QuantityPerUnit":"12 - 550 ml bottles","ReorderLevel":"25","SupplierID":"1","UnitPrice":"10000","UnitsInStock":"13","UnitsOnOrder":"70"},{"CategoryID":"2","Discontinued":"1","ProductID":"5","ProductName":"Chef Anton\u0027s Gumbo Mix","QuantityPerUnit":"36 boxes","ReorderLevel":"0","SupplierID":"2","UnitPrice":"21350","UnitsInStock":"0","UnitsOnOrder":"0"},{"CategoryID":"2","Discontinued":"0","ProductID":"3","ProductName":"Aniseed Syrup","QuantityPerUnit":"12 - 550 ml bottles","ReorderLevel":"25","SupplierID":"1","UnitPrice":"10000","UnitsInStock":"13","UnitsOnOrder":"70"}]

如何在Java android中通过arraylist通过产品ID,总和单价和数量进行JSON数据合并?

成为:

[{"CategoryID":"2","Discontinued":"0","ProductID":"3","ProductName":"Aniseed Syrup","QuantityPerUnit":"2","ReorderLevel":"25","SupplierID":"1","UnitPrice":"20000","UnitsInStock":"13","UnitsOnOrder":"70"},{"CategoryID":"2","Discontinued":"1","ProductID":"5","ProductName":"Chef Anton\u0027s Gumbo Mix","QuantityPerUnit":"36 boxes","ReorderLevel":"0","SupplierID":"2","UnitPrice":"21350","UnitsInStock":"0","UnitsOnOrder":"0"}]

0 个答案:

没有答案