【发布时间】:2021-07-28 08:52:09
【问题描述】:
json 有效载荷如下所示:
{
"clients": [
{
"scope": "scope1",
"claim": "scope1",
"id": ["123", "567"]
},
{
"scope": "scope2",
"claim": "claim2",
"id": ["321", "765"]
}
]
}
当尝试获取 pwsh 变量中的 json 时,我没有得到 id 值,它只显示 System.Object[]。
> $inputjson = (((get-content .\inputfile.json) -Join " " ) | convertfrom-json )
> echo $inputjson
clients
-------
{@{scope=scope1; claim=scope1; id=System.Object[]}, @{scope=scope2; claim=claim2; id=System.Object[]}}
任何关于如何获得这些数组值的帮助?
【问题讨论】:
-
您仍然可以访问这些值,尝试
$json.clients而不使用echo。和$json.clients[0].id例如将返回 scope1 的 ID -
@SantiagoSquarzon:谢谢。我可以访问它,但实际的问题是 API 不接受有效负载,因为“id”字段中有这个 System.Object[]。我正在使用
Invoke-RestMethod -Method POST -Headers $headers -Body $inputjson -Uri $uri调用 API
标签: c# powershell powershell-2.0 powershell-3.0 azure-powershell