Tôi có tập tin này mà tôi muốn đọc với PowerShell:"mảng không hợp lệ thông qua" khi phân tích cú pháp JSON
var myMap =
[
{
"name": "JSON Example",
"attr": "Another attribute"
}
]
My Mã PowerShell v3:
$str = Get-Content $file | Select -Skip 1;
$str | ConvertFrom-Json;
Nhưng tôi luôn nhận được lỗi này :
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
Nếu tôi sao chép và dán mã JSON bằng tay vào mã này, tất cả mọi thứ đang làm việc tốt:
'[
{
"name": "JSON Example",
"attr": "Another attribute"
}
]' | ConvertFrom-Json;
Nó hoạt động bây giờ! Cảm ơn lời giải thích! Tôi sẽ chấp nhận câu trả lời của bạn trong 4 phút. – ComFreek