当我尝试从powershell访问以下JSON文件时,它显示以下错误:Missing property name after reference operator.
这是我的JSON文件:
{
"Vnet": {
"Service": "VirtualNetwork",
"Name": "vnetname",
"ResourceGroupName": "RGname",
"Location": "Southeast Asia",
"Address_Prefix": "11.0.0.0/16",
"No_of_subnets": "1",
"Subnet": {
"1": {
"SubnetName":"sub1",
"Address_Prefix":"11.0.1.0/24"
}
}
}
}
这是简单的powershell命令
$file = (Get-Content "//filelocation" | Out-String) | ConvertFrom-Json
Write-Output $file.Vnet.Subnet.1.SubnetName
注意:我是JSON文件的作者,如果需要,我也可以对其进行任何更改。
答案 0 :(得分:1)
PowerShell似乎将1
误解为索引。把它放在引号中(以表明它是一个属性名称),代码将按预期工作:
Write-Output $file.Vnet.Subnet.'1'.SubnetName