以下の JSON レスポンス(文字コードはUTF-8)を返すURL に対して、
{
"bool": true,
"str": "abc123",
"int": 123,
"strJa": "日本語です"
}
PowerShell で curl.exe を使ってアクセスすると正常に表示されるけれど
PS> curl.exe -s https://mgng.mugbum.info/misc/json/run.php
{
"bool": true,
"str": "abc123",
"int": 123,
"strJa": "日本語です"
}
いったん変数に格納してから出力すると文字化けする。
PS> $response = curl.exe -s https://mgng.mugbum.info/misc/json/run.php
PS> Write-Output $response
{
"bool": true,
"str": "abc123",
"int": 123,
"strJa": "譌・譛ャ隱槭〒縺・
}
これを回避するには以下のように [System.Console]::OutputEncoding を UTF-8 にする。
PS> [System.Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("utf-8")
PS> $response = curl.exe -s https://mgng.mugbum.info/misc/json/run.php
PS> Write-Output $response
{
"bool": true,
"str": "abc123",
"int": 123,
"strJa": "日本語です"
}
≪ 2023-03-17
PC用モニター買った
2023-02-26 ≫
ふかやシティハーフマラソン走ってきた