小编jea*_*nat的帖子

PowerShell 中字典中的字典

所以,我对 PowerShell 相当陌生,只是不知道如何使用数组/列表/哈希表。我基本上想做Python描述的以下事情:

entries = {
    'one' : {
        'id': '1',
        'text': 'ok'
    },
    'two' : {
        'id': '2',
        'text': 'no'
    }
}

for entry in entries:
    print(entries[entry]['id'])
Run Code Online (Sandbox Code Playgroud)

输出:

1

2


但这在 PowerShell 中是如何工作的呢?我尝试过以下方法:

$entries = @{
    one = @{
        id = "1";
        text = "ok"
    };
    two = @{
        id = "2";
        text = "no"
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我不知道如何访问这些信息。

foreach ($entry in $entries) {
   Write-Host $entries[$entry]['id']
}
Run Code Online (Sandbox Code Playgroud)

=> 错误

powershell dictionary enumeration hashtable

4
推荐指数
1
解决办法
1574
查看次数

标签 统计

dictionary ×1

enumeration ×1

hashtable ×1

powershell ×1