在 Json 中解析 Json

罗伯特·汤普森

我正在 Jenkinsfile 中工作并尝试解析以下返回输出。我可以得到 uuid 但我不能得到name. 寻找一些指导。

詹金斯档案

    node('ansible'){
      stage('Get VM List'){
        def content = sh (returnStdout: true, script: "curl -X GET --header 'Content-Type: application/json' --header 'Accept: application/octet-stream' 'http://someurlapi'").trim()
        def vmList = readJSON text: content;

        //Works
        echo vmList[0].uuid
}}

返回输出

[
  {
    "num": XX,
    "ip": "XX.XX.XX.XX",
    "type": "KVM",
    "name": "machinename",
    "state": "Running",
    "ram": 4096,
    "ram-display": "4 GiB",
    "zpool": {
      "name": "zpool",
      "compression": "lz4",
      "mountpoint": "\/mnt",
      "mounted": true
    },
    "uuid": "d7622bd3-ed3d-5000-ae01-89ab294933r1",
    "autostart": false,
    "cpu": 2
  }]
罗伯特·汤普森

我发现我把它改成了

echo vmList[0]["name"]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章