我正在使用脚本来使用其API在Google Maps中搜索地点。我使用本地PC(Windows 10)作为开发环境。重要的代码部分如下:
$api_call_url ="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$lat,$lon&radius=$rad&type=$place_type&key=$Api_Key"
$api_call_response=Invoke-WebRequest $api_call_url
$api_call_obj = ConvertFrom-Json -InputObject $api_call_response
Add-Content "$file_name_json" $api_call_response
Google返回的json存储在$ api_call_response变量中,然后使用Add-Content附加到文本文件中。脚本完成并经过测试后,我将其移至生产环境(Windows Server 2016 Std)。运行脚本,发现将json写入文本文件的方式不同。
这就是从Windows 10 PC写入文本文件的内容(每个结果多行)
{
"html_attributions" : [],"results" : [],"status" : "ZERO_RESULTS"
}
{
"html_attributions" : [],"status" : "ZERO_RESULTS"
}
这是从Windows Server 2016中写入文本文件的内容(每个结果一行)
{ "html_attributions" : [],"status" : "ZERO_RESULTS"}
{ "html_attributions" : [],"status" : "ZERO_RESULTS"}
如果我将变量$ api_call_response写输出到屏幕,它将显示多行。
我需要多行输出,因为还有另一个脚本可以从不需要的结果中清除文件,并且由于生成的文本文件中附加了许多json,因此只能从所有json中创建一个json文件。但是它希望结果文件能像我的开发环境编写它那样。显然,我试图避免修改清理脚本。
PSVersion on Windows Server 2016: 5.1.14393.3053
PSVersion on Windows 10: 5.1.17763.771
有什么想法吗?