I receive result on API JSON. But Russian letters are displayed as question marks. Any ideas, comrades? thanks in advance

What I run:

$url2 = "http://********/rooms?limit=3&access_token=******" $rres = Invoke-WebRequest -Method GET -Uri $url2 -ContentType "application/json;charset=utf-8" | ConvertFrom-Json $Lmres = $rres.chunk Write-Host $Lmres[0].Content 

I receive:

 @{body=???? ??????) ; msgtype=m.text} @{body=??????????????; msgtype=m.text} @{body=??????????; msgtype=m.text} 

The coding of the request to json changed to win-1251, nothing has changed.

    1 answer 1

    In this line:

     $rres = Invoke-WebRequest -Method GET -Uri $url2 -ContentType "application/json;charset=utf-8" 

    You do not specify the response encoding, but the encoding of the request. It is necessary to change the encoding of the already returned data. I can not emulate exactly your request, since the address is unknown, but it should look something like this:

     $rus_result = [System.Text.Encoding]::GetEncoding('windows-1251').GetString([Byte[]]$your_result) 

    or the same, but with utf-8 instead of windows-1251

    • Good day. Says the following: Cannot convert the "bytes" argument, with the value: "???? ??????)", for "GetString" to the type "System.Byte []": "Can't convert the value" ?? ?? ??????) "to type" System.Byte [] ". Error:" Unable to convert the value "???? ??????)" to the type "System.Byte". Error: "The input string had the wrong format." "" - technor
    • @technor is logical, you need a conversion ([Byte []]), now I ’m adding an answer - Viktor Tomilov