如果我有一个 JSON 对象列表的输入。我如何按日期在Java 中嵌套数据,然后按日期按降序排列类别?输入: { "data":[{ "date": "2015-02-26", "buyer": "Ryan", "category": "clothes", "quantity":"10.0" }, { "date": "2015-02-18", "buyer": "Lisa", "category": "food", "quantity": "2.0" }, { "date": "2015-02-18", "buyer": "Brian", "category": "food", "quantity": "11.0", }, { "date": "2015-02-26", "buyer": "Jim", "category": "clothes", "quantity": "20.0", }, { "date": "2015-02-26", "buyer": "Tom", "category": "food", "quantity": "40.0", }, { "date": "2015-02-18", "buyer": "Alyssa", "category": "clothes", "quantity": "13.0", }]}您可以在下面的输出中看到,我首先尝试按日期对数据进行分组,然后在该日期内按类别对对象进行分组。期望输出:{ "2015-02-26”:{ “clothes”:[{ "date": "2015-02-26", "buyer": "Ryan", "category": "clothes", "quantity":"10.0" }, { "date": "2015-02-26", "buyer": "Jim", "category": "clothes", "quantity": "20.0", }], "food":[{ "date": "2015-02-26", "buyer": "Tom", "category": "food", "quantity": "40.0", }] }
1 回答
慕斯709654
TA贡献1840条经验 获得超5个赞
出人意料的轻松。
规格
[
{
"operation": "shift",
"spec": {
"data": {
// Ex. send the first data item to
// 2015-02-26.clothes[]
// where we want clothes to always be an array
// even if it only got one value assigned to it.
"*": "@(0,date).@(0,category)[]"
}
}
}
]
添加回答
举报
0/150
提交
取消