我有这个 json 数据,并且我只想解析其中的版本:8.9,可以这样做吗?
{
"version": "8.9",
"description": "Long-Term Support version - Hardening for long-term reliability, bug fixes and small improvements",
"releaseDate": "2021-05-04",
"changeLogUrl": "https://jira.sonarsource.com/secure/ReleaseNote.jspa?projectId=10930&version=16710",
"downloadUrl": "https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.0.43852.zip",
"plugins": {
"requireUpdate": [
{
"key": "codehawk",
"name": "Codehawk Java",
"category": "External Analysers",
"description": "Analyze Java code smell",
"homepageUrl": "https://github.com/SDPMLab/CodeHawk",
"editionBundled": false,
"version": "1.5"
},
答案1
只要json
正确关闭,就像
{
"version": "8.9",
"description": "Long-Term Support version - Hardening for long-term reliability, bug fixes and small improvements",
"releaseDate": "2021-05-04",
"changeLogUrl": "https://jira.sonarsource.com/secure/ReleaseNote.jspa?projectId=10930&version=16710",
"downloadUrl": "https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.0.43852.zip",
"plugins": {
"requireUpdate": [
{
"key": "codehawk",
"name": "Codehawk Java",
"category": "External Analysers",
"description": "Analyze Java code smell",
"homepageUrl": "https://github.com/SDPMLab/CodeHawk",
"editionBundled": false,
"version": "1.5"
}
]
}
}
... 您可以使用jq
:
jq -r '.version' data.json
您可能需要安装jq
:
sudo apt install jq