Groovy 从JSON负载中删除特定节点,保持子节点完整
我是groovy的新手,需要帮助。我需要在下面的有效负载中删除一个段(段='ToBeRemoved'),并且需要在groovy中这样做。通过谷歌尝试了一些代码,但没有多大进展,任何人都可以帮助 输入:Groovy 从JSON负载中删除特定节点,保持子节点完整,groovy,Groovy,我是groovy的新手,需要帮助。我需要在下面的有效负载中删除一个段(段='ToBeRemoved'),并且需要在groovy中这样做。通过谷歌尝试了一些代码,但没有多大进展,任何人都可以帮助 输入: { "Root": { "Somedata": true, "Myoperation": { "Row": [ {
{
"Root": {
"Somedata": true,
"Myoperation": {
"Row": [
{
"Action": "CreateOrUpdate",
"Object": {
"a": true,
"b": "test",
"c": "test"
}
}, {
"Action": "CreateOrUpdate",
"Object": {
"Action": "CreateOrUpdate",
"Object": {
"e": true,
"f": "test",
"g": "test"
},
"O1": {
"ToBeRemoved": [
{
"Key": 4
}, {
"Key": 4
}, {
"Key": 4
}, {
"Key": 4
}, {
"Key": 4
}
]
},
"O2": {
"ToBeRemoved": [
{
"Key": "7e6184bb94576c9d"
}, {
"Key": "ca6da5d833b6866f"
}, {
"Key": "ca6da5d833b6866f"
}
]
},
"O3": {
"ToBeRemoved": [
{
"Key": 4.00210590000900225
}, {
"Key": 4.00210590000900225
}, {
"Key": 4.00210610200900225
}
]
}
}
}
]
}
}
}
输出
{
"Root": {
"Somedata": true,
"Myoperation": {
"Row": [
{
"Action": "CreateOrUpdate",
"Object": {
"a": true,
"b": "test",
"c": "test"
}
}, {
"Action": "CreateOrUpdate",
"Object": {
"Action": "CreateOrUpdate",
"Object": {
"e": true,
"f": "test",
"g": "test"
},
"O1": [
{
"Key": 4
}, {
"Key": 4
}, {
"Key": 4
}, {
"Key": 4
}, {
"Key": 4
}
],
"O2": [
{
"Key": "7e6184bb94576c9d"
}, {
"Key": "ca6da5d833b6866f"
}, {
"Key": "ca6da5d833b6866f"
}
],
"O3": [
{
"Key": 4.00210590000900225
}, {
"Key": 4.00210590000900225
}, {
"Key": 4.00210610200900225
}
]
}
}
]
}
}
}
我试图解析输入的代码
JsonSlurper slurper=新JsonSlurper()
Map parsedJson=slurper.parseText(正文)
String segments=parsedJson.get(“MultiOperation”).get(“Operations”).get(“Row”)。您试图实际删除映射的内容是什么?它是如何失败的?