我有一大堆jsonObjects的jsonArray,我想通過market_id進行分組,這樣具有類似market_id的對象分別存放在自己的列表或數組中。我怎樣才能做到這一點?在jsonArray中對jsonObjects進行分組Android
[
{
"product_id": "12301",
"selection": "No",
"sales": "31",
"market_id": "10",
},
{
"product_id": "12302",
"selection": "No",
"sales": "24",
"market_id": "43",
},
{
"product_id": "12303",
"selection": "Yes",
"sales": "121",
"market_id": "10",
},
{
"product_id": "12304",
"selection": "No",
"sales": "0",
"market_id": "43",
},
{
"product_id": "12305",
"selection": "Yes",
"sales": "20",
"market_id": "43",
},
]
爲了實現這樣的事情:
[{
"product_id": "12304",
"selection": "No",
"sales": "0",
"market_id": "43",
},
{
"product_id": "12305",
"selection": "Yes",
"sales": "20",
"market_id": "43",
},
{
"product_id": "12302",
"selection": "No",
"sales": "24",
"market_id": "43",
},]
我想你應該根據該先檢查ID您做出類似ID –
你嘗試過什麼到目前爲止JSON陣列?顯示你的代碼。 –
@Bmbariah如果你按market_id分組,你的product_id怎麼樣?在JSON中查看您的product_id對於每個market_id都是不同的。 –