groovy - 从 JSON 有效负载中删除特定节点,保持子节点完整
问题描述
我是 groovy 的新手,需要帮助。我需要在下面的有效负载中删除一个段(segment = 'ToBeRemoved'),并且需要在 groovy 中执行此操作。通过谷歌尝试了一些代码,但进展不大,任何人都可以帮忙。
输入:
{
"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 = new JsonSlurper() Map parsedJson = slurper.parseText(body)
字符串段 = parsedJson.get("MultiOperation").get("Operations").get("Row")。
解决方案
推荐阅读
- phaser-framework - 有一种方法可以防止 Phaser 3 中精灵的初始“下降”吗?
- ios - overlaySKScene 无法通知主 SCNScene
- c# - 如何在 GroupBox 中设置所有文本和文本颜色标签?
- oracle - 想在oracle存储过程中找到非连续数的起点和终点
- common-lisp - 我应该通过什么文档类型来获取类的文档?
- haskell - 为什么 GHC.Types.Any 在这里?
- python - 用 None 替换 DataFrame 中的值
- postgresql - 如何在 PostgreSQL 中从 1 开始我的序列号
- r - 我可以在 R 中创建一个 for 循环来保存图像吗?
- c# - 如何同时容纳 32 位和 64 位 odbc 驱动程序