【发布时间】:2021-01-06 05:33:09
【问题描述】:
我正在使用下面的代码使用 PowerShell 重新生成我的 Json,但是它会在 json { 标记开始之前创建意外字符。
<#$data = Get-Content -Raw -Path myfile.json | ConvertFrom-Json#>
$data = @"
{
"stations": [
{
"code": "1",
"name": "United force"
},
{
"code": "2",
"name": "Toowoon Bay Service Station"
}
],
"prices": [
{
"stationcode": "1",
"fueltype": "DL",
"price": 126.97
},
{
"stationcode": "1",
"fueltype": "E10",
"price": 118.92
},
{
"stationcode": "2",
"fueltype": "E10",
"price": 112.90
},
{
"stationcode": "2",
"fueltype": "P95",
"price": 125.90
},
{
"stationcode": "2",
"fueltype": "P98",
"price": 155.90
},
{
"stationcode": "2",
"fueltype": "U91",
"price": 115.20
}
]
}
"@ | ConvertFrom-Json
foreach ($price in $data.prices) {
$data.stations |
Where-Object { $_.code -eq $price.stationcode } |
Add-Member -MemberType NoteProperty -Name $price.fueltype -Value $price.price
}
$data | Select-Object -Property stations | ConvertTo-Json | Set-Content "testJson.json" -Encoding UTF8
上传后调用此文件时,由于该意外字符,我无法读取 json 文件。
希望有人可以在 PowerShell 代码中提供帮助,以确保没有这样的字符,我可能正在做一些简单的事情,但不确定如何。
我正在读取PowerShell到Flutter之后生成的json文件,抛出如下所示的错误
谢谢,
【问题讨论】:
-
get-content -encoding utf8
标签: json powershell flutter character