我有以下 JSON 作为输出:-
def desiredJson = '{"count": 4, "max": "12", "min": 0, "details": [{"goBus": {"first": 12800, "second": 11900, "third": 12800},"goAir": {"first": 12800, "second": 11900, "third": 12800}, "gotTrain": {"first": 12800, "second": 11900},"sell": true, "darn": 2,"rate": [{ "busRate": 11900, "flag": false, "percent": 0}],}],}'
我想删除“计数”键及其值,删除
"goBus": {
"first": 12800,
"second": 11900,
"third": 12800
},
并删除“详细信息”节点的方括号。
我试过下面的代码来删除和替换为空: -
def slurper = new JsonSlurper();
def json = slurper.parse(file)
def newjson = JsonOutput.toJson(json).toString()
String j = "max"
newjson = newjson.replaceAll(""+ j +"", "")
log.info newjson
作为输出,最大值不会被删除。或者有没有其他方法可以从 JSON 中删除这些所有东西。
有人可以帮我吗?
我也试过这个: -
def json = new JsonSlurper().parseText(desiredJson)
def njson = json.details.goBus
def pjson = njson.remove()
log.info JsonOutput.toJson(pjson)
它返回错误。