gpt4 book ai didi

java - 从 java 中的大型 JSON 文件中提取特定文本(密码字符串),而不使用 JSON 帮助器类

转载 作者:行者123 更新时间:2023-12-02 10:05:14 32 4
gpt4 key购买 nike

我有以下从特定 REST 调用收到的大型 JSON。我只想提取密码字符串(以粗体突出显示)。所以我需要值(value)观。java中的ConfigPWD_USER.passwordConfigPWD_ROOT.passwordinstanceOwnerPassworddatabaseUserPasswordfencedUserPassword 。我想我必须使用字符串正则表达式进行搜索。有人可以帮忙吗?

{
"deployment_name": "name1",
"model": {
"model": {
"description": "",
"nodes": [{
"id": "OS Node",
"ptype": "image:OS Node",
"attributes": {
<more json key value pairs>
**"ConfigPWD_USER.password": "<xor>NzozMzA=",
"ConfigPWD_ROOT.password": "<xor>NzozMzA="**
},
"type": "image:OS,
"groups": {},
"locked": []
}, {
"id": "disk for db instance",
"attributes": {
<more json key value pairs>
},
"type": "add disk:1.0.0",
"groups": {},
"locked": []
}, {
"id": "disk for database data",
"attributes": {
<more json key value pair>
},
"type": "disk:1.0.0",
"groups": {},
"locked": []
}, {
"id": "DB Server",
"startsAfter": ["disk for db instance",
"OS Node"
],
"locked": ["instanceMountPoint", "instanceMountPoint", "instanceMountPoint"],
"attributes": {
"instanceMountPoint": "${disk for db instance.MOUNT_POINT}",
<more json key value pair>
**"instanceOwnerPassword": "<xor>NzozMzA=",**
<more json key value pair>
**"fencedUserPassword": "<xor>NzozMzA=",**

},
"type": "DBLUN",
"groups": {}
}, {
"id": "bludbs",
"startsAfter": ["DB Server", "disk for database data"],
"locked": ["instanceName", "dataMountPoint", "instanceName", "dataMountPoint", "instanceName", "dataMountPoint"],
"attributes": {
<many json key value pairs>,
**"databaseUserPassword": "<xor>NzozMzA="**,
<many json key value pairs>
},s
"type": "sript:scrip1.exe",
"groups": {}
}],
"app_type": "application",
"name": "Default DB in Linux",
"patterntype": "vsys",
"links": [{
"id": "HostedOnLink_1",
"source": "disk for db instance",
"target": "OS Node",
"attributes": {},
"type": "HostedOnLink",
"groups": {}
},
{
"id": "HostedOnLink_2",
"source": "disk for database data",
"target": "OS Node",
"attributes": {},
"type": "HostedOnLink",
"groups": {}
}, {
"id": "HostedOnLink_3",
"source": "DB Server",
"target": "OS Node",
"attributes": {},
"type": "HostedOnLink",
"groups": {}
}, {
"id": "HostedOnLink_4",
"source": "bludb",
"target": "OS Node",
"attributes": {},
"type": "HostedOnLink",
"groups": {}
}
],
"locked": false,
"readonly": false,
"version": "1.0",
"patternversion": "1.2.3.0",
"mixinArgs": null
},
"layers": [{
"id": "layer",
"nodes": ["OS Node", "disk for db instance", "disk for database data", "DB Server", "bludb"]
}]
},
<more json key value pairs>,
"organizations": []
}

最佳答案

在 groovy 中,有内置 groovy.json.JsonSlurper ,查找其中一个值的代码可能如下所示:

def json = new groovy.json.JsonSlurper().parseText('''
{
"deployment_name": "name1",
"model": {
"model": {
"description": "",
"nodes": [{
"id": "OS Node",
"ptype": "image:OS Node",
"attributes": {
"ConfigPWD_USER.password": "1<xor>NzozMzA=",
"ConfigPWD_ROOT.password": "1<xor>NzozMzA="
},
"type": "image:OS",
"groups": {},
"locked": []
}, {
"id": "disk for db instance",
"attributes": {
"ConfigPWD_USER.password": "2<xor>NzozMzA=",
"ConfigPWD_ROOT.password": "2<xor>NzozMzA="
},
"type": "add disk:1.0.0",
"groups": {},
"locked": []
}]
}
}
}
''')

json.model.model.nodes.collect{n-> n.attributes."ConfigPWD_USER.password" }

关于java - 从 java 中的大型 JSON 文件中提取特定文本(密码字符串),而不使用 JSON 帮助器类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55376890/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com