【发布时间】:2013-05-10 15:17:25
【问题描述】:
考虑采用这种格式的 JSON:
"Stuffs": [
{
"Name": "Darts",
"Type": "Fun Stuff"
},
{
"Name": "Clean Toilet",
"Type": "Boring Stuff"
}
]
在 PowerShell 3 中,我们可以获得 Stuffs 列表:
$JSON = Get-Content $jsonConfigFile | Out-String | ConvertFrom-Json
假设我们不知道列表的确切内容,包括对象的顺序,我们如何检索具有特定名称字段值的对象?
蛮力,我们可以遍历列表:
foreach( $Stuff in $JSON.Stuffs ) {
但我希望存在更直接的机制(类似于 C# 中的 Lync 或 Lambda 表达式)。
【问题讨论】:
标签: json powershell powershell-3.0