非常初级的问题。我正在尝试使用PowerShell从JSON获取特定的值。具体来说,我想列出以下服务:TEST00000 和 FAKE。
当我运行下面的脚本时,我得到了这个结果:
TEST00000 FAKE
--------- ----
@{Enabled=True; Processed=2; Sent=3; Failed=4; Downloaded=5} @{Enabled=True}
如何获取仅包含服务的列表?
更重要的是,如何列出仅包含具有键/值Enabled=True的服务的列表?
以下是代码:
$JSON = '{
"Envs": {
"DEV": {
"Services": {
"TEST00000": {
"Enabled": true,
"Processed": 2,
"Sent": 3,
"Failed": 4,
"Downloaded": 5
},
"FAKE": {
"Enabled": true
}
}
}
},
"Component": {
"Digger": {
"Envs": {
"DEV": {
"DownloadE": 4
}
}
}
}
}'
$jsonobj = ConvertFrom-Json -inputObject $JSON
$jsonobj.Envs.DEV.Services
psobject
属性(已经太久了,记不清是谁了)。 - BenHEnabled
属性是一个布尔值。当你尝试将字符串'false'
转换为布尔值时,它会变成$True
。你可以用[bool]'false'
进行测试。 - BenH