powershell JSON输出GoogleMap地理编码API在地址、浏览器正确输出中返回问号

inkz8wg9  于 2022-11-10  发布在  Shell
关注(0)|答案(1)|浏览(145)

我已经创建了一个脚本:

$API    = "<That is secret>"
$LatLng = "47.5560960732389,7.5917686522"
$URL = "https://maps.googleapis.com/maps/api/geocode/json?latlng=$LatLng&key=$API"
$URL
$Result = Invoke-WebRequest -Uri $URL -ContentType "application/json; charset=UTF-8" -Method Get -UseBasicParsing | ConvertFrom-Json 

if($Result.status -eq "OK")
 {
  $Result.results.formatted_address
  Write-Host "------------------------------------"
  $Result.results.formatted_address[0]
  [Text.Encoding]::UTF8.GetString([Text.Encoding]::GetEncoding(28591).GetBytes($Result.results.formatted_address[0]))
 }

输出结果如下所示:

M??nsterpl. 12, 4051 Basel, Switzerland
M??nsterpl. 14, 4051 Basel, Switzerland
M??nsterpl. 14, 4051 Basel, Switzerland
M??nsterberg 13, 4051 Basel, Switzerland
HH4R+CP Basel, Switzerland
M??nsterpl. 9, 4051 Basel, Switzerland
Altstadt Grossbasel, Basel, Switzerland
4051 Basel, Switzerland
Basel, Switzerland
Basel-Stadt, Switzerland
Basel City, Switzerland
Switzerland
------------------------------------
M??nsterpl. 12, 4051 Basel, Switzerland
M??nsterpl. 12, 4051 Basel, Switzerland

如果我在Firefox中输入创建的URL(存储在变量$URL中)复制并粘贴,地址将以正确的布局显示:

我可以做些什么来解决这个问题?谢谢..。StingPilot

o4hqfura

o4hqfura1#

$Result = Invoke-WebRequest -Uri $URL -Method Get -UseBasicParsing
$Result = ($Result.Content | ConvertFrom-JSON)

只有这个管用..。

相关问题