我有这个文件,我想用 PowerShell 读取:
var myMap =
[
{
"name": "JSON Example",
"attr": "Another attribute"
}
]
我的 PowerShell v3 代码:
$str = Get-Content $file | Select -Skip 1;
$str | ConvertFrom-Json;
但我总是收到这个错误:
ConvertFrom-Json : Invalid array passed in, ']' expected. (1): [
At S:\ome\Path\script.ps1:60 char:8
+ $str | ConvertFrom-Json;
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
如果我将 JSON 代码手动复制并粘贴到代码中,一切正常:
'[
{
"name": "JSON Example",
"attr": "Another attribute"
}
]' | ConvertFrom-Json;