仅在 Powershell 中枚举 JSON 结果时查看' rows=System.Object[] '



我正在返回一个web服务调用,该调用应该以json格式返回,而且它看起来确实是有效的json。作为一个字符串,它看起来像这样:

{"总计":10,"行":[{"进程":"VISIO.EXE","computer_id":57,"last_used":"2016-04-20T01:34:09Z"},{"过程":"VISIO.EXE","computer_id":64,"last_used":"2016-04-01T04:09:35Z"},{"进程:"VISIO.EXE","computer_id":181,"last_used":"2016-03-10T23:02:53H"}2016-04-19T05:31:32Z"},{"process":"VISIO.EXE","computer_id":237,"last_used":"2016-04-04T10:23:23Z"},{"process":"VISIO.EXE","computer_id":284,"last_used":"2016-04-15T10:54:29Z"},{":"2016-05-11T00:49:11Z"},{"进程":"VISIO.EXE","computer_id":10198,"last_used":"2016-05-06T06:59:29Z"}}

我正试图使用以下脚本来枚举结果。我已经尝试了所有列出的选项1-4,每次取消一个选项的注释,但我无法返回多个结果。

你知道我做错了什么吗?

$url = 'https://servername:port/api/sam/raw_app_usage_property_values?criteria={"and":[["process","=","visio.exe"]]}&limit=100&columns[]=process&columns[]=computer_id&columns[]=last_used'
# option 1. get all results, we see a full list of processes, full string returned
#$results = Invoke-WebRequest -Uri $url -Method GET -Headers $headers
#write-host $results
# option 2. get all results but break them down as part of the request. Only one result returned - @{total=10; rows=System.Object[]}
#$results = Invoke-WebRequest -Uri $url -Method GET -Headers $headers | ConvertFrom-Json
#write-host $results
# option 3. use a different method, which supposedly breaks down the request natively. Only one result returned - @{total=10; rows=System.Object[]}
#$results = Invoke-RestMethod -Uri $url -Method GET -Headers $headers
#write-host $results
# option 4. get content directly from file, only one result returned - @{total=10; rows=System.Object[]}
#$results = (Get-Content -path "C:tempraw_app_usage_property_values.json" -raw)
# is there anything in the array?
foreach ($result in $results) {
    write-host $result
}

您似乎正在取回数据。请记住,返回的对象有两个属性,"total"one_answers"rows"。

尝试:

foreach ($result in $results.rows) {
    write-host $result
}

相关内容

最新更新