Powershell调用RestMethod返回JSON
我使用PowerShell每天运行一个php脚本。我似乎无法从Powershell调用RestMethod返回JSON,json,powershell,powershell-2.0,psobject,Json,Powershell,Powershell 2.0,Psobject,我使用PowerShell每天运行一个php脚本。我似乎无法从Invoke RestMethod返回json。如何才能做到这一点 以下是我正在使用的代码: $limit = 200; for ($i=1; $i -le $limit; $i++) { Write-Host $i started of $limit $Site = "http://example.com/updates" $Info = Measure-C
Invoke RestMethod
返回json
。如何才能做到这一点
以下是我正在使用的代码:
$limit = 200;
for ($i=1; $i -le $limit; $i++)
{
Write-Host $i started of $limit
$Site = "http://example.com/updates"
$Info = Measure-Command{
$data = @{call_type = 'powershell'}
$resp = (Invoke-RestMethod -Method Post -URI $Site -Body $data -TimeoutSec 500).results
}
Write-Host resp - On $resp.date, $resp.num were downloaded
Write-Host $i took $Info.TotalSeconds s
Write-Host ---------------------------------------
}
PHP脚本正在传回一个json字符串,如:
{date: '2014-09-30', num: 127569}
您不需要
.results
<代码>调用RestMethod自动将JSON转换为[PSObject]
如果您想要获得原始JSON,那么使用
调用WebRequest
,但是由于您引用了$resp.date
和$resp.num
,似乎您希望它毕竟为您进行转换。您不需要.results
<代码>调用RestMethod自动将JSON转换为[PSObject]
如果您想要获得原始JSON,那么使用调用WebRequest
,但是由于您引用了$resp.date
和$resp.num
,似乎您希望它毕竟为您进行转换