【发布时间】:2020-10-17 16:14:55
【问题描述】:
我有以下 json。我只想从下面的响应中提取“id”:“41”中的值 41。假设我不知道该值是什么,我如何提取该单个值,将其分配给变量并查看输出?
{
"page": {
"offset": 0,
"total": 36,
"totalFilter": 1
},
"list": [
{
"id": "41",
"type": "ATBR",
"hostName": "AAMS",
"userId": "",
"userName": "",
"status": "CONNECTED",
"poolName": "",
"fullyQualifiedHostName": "-",
"updatedBy": "mscr",
"updatedOn": "2020-06-24T23:28:11.239894Z",
"botAgentVersion": "9.0"
}
]
}
到目前为止,我有以下内容,但我不知道如何只获取单个值
$json = @"
{
"page": {
"offset": 0,
"total": 36,
"totalFilter": 1
},
"list": [
{
"id": "41",
"type": "ATBR",
"hostName": "AAMS",
"userId": "",
"userName": "",
"status": "CONNECTED",
"poolName": "",
"fullyQualifiedHostName": "-",
"updatedBy": "mscr",
"updatedOn": "2020-06-24T23:28:11.239894Z",
"botAgentVersion": "9.0"
}
]
}
"@
$x = $json | ConvertFrom-Json
$x.list[0]
$id = $x.list | Where { $_.list -eq "id" }
我当前的输出结果如下。我只想从中提取 41 个。
id : 41
type : ATBR
hostName : AAMS
userId :
userName :
status : CONNECTED
poolName :
fullyQualifiedHostName : -
updatedBy : mscr
updatedOn : 2020-06-24T23:28:11.239894Z
botAgentVersion : 9.0
非常感谢任何帮助 - 在此先感谢
【问题讨论】:
-
$id = ($x.list | where id).id.
标签: json powershell extract