小编Anu*_*ram的帖子

如果使用powershell在键中有短划线( - ),如何读取json中的值

鉴于这个Json:

{
 “StudentInfo":{
   “first-name": “xyz",
   “Student_id": "123-xyz"
 }
}
Run Code Online (Sandbox Code Playgroud)

我可以使用下面的代码读取student_id的值.

$config = Get-Content -Raw $Config
$configObject = ConvertFrom-Json –InputObject $config
$StudentId = $configObject.StudentInfo.Student_id
Run Code Online (Sandbox Code Playgroud)

但是,我无法读取"first-name"的值,因为powershell将其视为命令而不是变量.更改密钥名称对我来说不是一个选项.

如何使用powershell 5.1检索"first-name"的值?

powershell json

3
推荐指数
1
解决办法
152
查看次数

标签 统计

json ×1

powershell ×1