Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell调用RestMethod返回JSON_Json_Powershell_Powershell 2.0_Psobject - Fatal编程技术网

Powershell调用RestMethod返回JSON

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

我使用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-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
,似乎您希望它毕竟为您进行转换