我在我的PowerShell脚本中有这段代码,但是它无法处理特殊字符的部分。
$request = 'http://151.80.109.18:8082/vrageremote/v1/session/players'
$a = Invoke-WebRequest -ContentType "application/json; charset=utf-8" $request |
ConvertFrom-Json |
Select -expand Data |
Select -expand players |
Select displayName, factionTag | Out-file "$scriptPath\getFactionTag.txt"
在我的输出文件中,任何特殊字符都只显示为'????'。有人知道如何让它在我的输出文件中显示特殊字符吗?
Invoke-WebRequest
响应的.Content
属性来进行操作。 - mklement0Invoke-RestMethod
调用的头对象中使用-ContentType“application/json; charset=utf-8”,但它没有起作用,将其作为单独的参数传递给Invoke-RestMethod -ContentType“application/json; charset=utf-8”
则完美地解决了问题。 - Shrikant Prabhu