给定这个 Json:
{
“StudentInfo":{
“first-name": “xyz",
“Student_id": "123-xyz"
}
}
我可以使用下面的代码读取student_id的值。
$config = Get-Content -Raw $Config
$configObject = ConvertFrom-Json –InputObject $config
$StudentId = $configObject.StudentInfo.Student_id
但是,我无法读取"名字"的值,因为 powershell 将其视为命令而不是变量。更改密钥名称对我来说不是一个选项。
如何使用 powershell 5.1 检索"名字"的值?
使用引号:
$configObject.StudentInfo.'first-name'