powershell - 使用powershell获取json键值

标签 powershell

我有以下 json 输出字符串:

{
    "meta": {
        "limit": 20,
        "next": null,
        "offset": 0,
        "previous": null,
        "total_count": 1
    },
    "objects": [{
        "bcontext": "/api/v2.0/buildercontext/2/",
        "bugs": [],
        "build": {
            "bldtype": "obj",
            "branch": "main",
            "buildstatus": [{
                "build": "/api/v2.0/build/2140634/",
                "failurereason": "_checkfailures (seen: FAIL - /testrun/18647678/ - area[4769] AIM-SANITY)",
                "id": "1294397",
                "lastupdate": "2015-03-31T14:30:18",
                "overridden": false,
                "overridedesc": "",
                "overrideuser": null,
                "recommended": false,
                "resource_uri": "/api/v2.0/buildstatus/1294397/",
                "slatype": {
                    "id": "26",
                    "name": "VA_Bats",
                    "resource_uri": "/api/v2.0/sla/26/"
                }
            }],
            "changeset": "494625",
            "coverage": false,
            "deliverables": ["/api/v2.0/deliverable/4296455/", "/api/v2.0/deliverable/4296956/", "/api/v2.0/deliverable/4296959/", "/api/v2.0/deliverable/4296986/", "/api/v2.0/deliverable/4296992/", "/api/v2.0/deliverable/4296995/", "/api/v2.0/deliverable/4297034/", "/api/v2.0/deliverable/4297058/"],
            "git_host": null,
            "git_repo": null,
            "id": "2140634",
            "p4host": {
                "id": "10",
                "p4port": "perforce-rhino.eng.com:1800",
                "p4weburl": "http://p4web.eng.com:1800",
                "resource_uri": "/api/v2.0/perforceserver/10/"
            },
            "resource_uri": "/api/v2.0/build/2140634/",
            "site": "/api/v2.0/site/25/",
            "site_name": "mbu",
            "slastested": ["/api/v2.0/sla/26/"],
            "submit_time": "2015-03-31T05:40:21",
            "submit_user": "haharonof"
        },
        "builder": "/api/v2.0/builder/1423/",
        "clean": true,
        "componentbuilds": "vcops-vsphere-solution-pak=sb-5242047,vrops=sb-5242013,vscm=sb-5242025,vsutilities=sb-5242029;parentbuilder=1410",
        "deleted": false,
        "endtime": "2015-03-31T06:20:58",
        "helpzillas": [],
        "id": "4296956",
        "location": {
            "httpserver": "sc-prd-cat-services001.eng.com",
            "id": "1",
            "name": "PA",
            "nfsserver": "cat-results.eng.com",
            "pxedir": "/mts/builder-pxe",
            "resource_uri": "/api/v2.0/location/1/",
            "resultspath": "/results"
        },
        "nfsserver": "build-storage60",
        "p4client": "vmktestdevnanny-builder-1423",
        "path": "/storage60/release/sb-5242148",
        "ready": true,
        "resource_uri": "/api/v2.0/deliverable/4296956/",
        "result": "PASS",
        "sbbuildid": 5242148,
        "sbjobid": 5242148,
        "sbuser": "arajamanickam",
        "starttime": "2015-03-31T06:16:50",
        "targetchangeset": "494625",
        "targets": "vcopssuitevm",
        "triagetime": null,
        "vmodl": null
    }]
}

我要获取sbbuildid使用 PowerShell。我怎样才能得到这个?

最佳答案

通过将您的 json 转换为对象,使用 ConvertFrom-Json cmdlet (假设 $jsonString 包含上面的 json):

$jsonObj = $jsonString | ConvertFrom-Json
$jsonObj.objects.sbbuildid

关于powershell - 使用powershell获取json键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29488654/

相关文章:

powershell - 使用 powershell 路径中存在非法字符

powershell - PowerShell 是否具有 "window"函数?

powershell - 如何确保一次只运行一个脚本实例?

powershell - DSC 资源中是否可以有可选的 Key 属性?

powershell - 如何使用 PowerShell 从数组中的项目中删除字符

powershell - 在powershell中格式化每行命令输出

testing - Powershell 用于 web-ui 测试的优势?

node.js - 在 Node js 上安装必要的包时出错

regex - 正则表达式以选择UNC中的最后一个文件夹

xml - 如何使用 PowerShell 使用 XML 路径变量读取 XML 文件中的 CDATA?