如何显示 JSON 输出?
How to display JSON output?
第一个 API 呼叫:
https://proto123.hipchat.com/v2/user?auth_token=2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
当我 运行 这个 URI 时,我得到了用户 ID。
然后我需要为从前一个 URI 生成的每个用户 ID 执行下一个 URI:
https://proto123.hipchat.com/v2/user/id?auth_token=2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
然后将输出文件打印为 CSV。
我该怎么做?
请检查这个脚本:
$uri = "https://proto123.hipchat.com/v2/user?auth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
try {
$webResponse = Invoke-RestMethod -uri $uri -ContentType "application/json"
} catch {
$webResponse = $_.Exception.Response
}
if ($webResponse) {
Write-Debug "Output result"
$webResponseIDList = @() # Defining array for collecting the ID's
foreach ($webResponseID in $webResponse) {
$webResponseIDList += [PSCustomObject] @{
id = $webResponseID.id
} # End of ID's Array
$id = $webResponseID.id
Write-Host "User ID is : $id" + $webResponseIDList `r`n
$uri = "https://proto123.hipchat.com/v2/user/$id?auth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$webResponseID = Invoke-RestMethod -uri $uri -ContentType "application/json"
Write-Host "User ID are :" + $webResponseID.id `r`n
Write-Output "User ID are :" + $webResponseID.id `r`n
}
} else {
Write-Debug "No results were returned"
}
我没有在 PowerShell 中获得输出。
改变
foreach ($webResponseID in $webResponse) {
...
}
至
foreach ($webResponseID in $webResponse.items) {
...
}
第一个 API 呼叫:
https://proto123.hipchat.com/v2/user?auth_token=2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
当我 运行 这个 URI 时,我得到了用户 ID。
然后我需要为从前一个 URI 生成的每个用户 ID 执行下一个 URI:
https://proto123.hipchat.com/v2/user/id?auth_token=2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
然后将输出文件打印为 CSV。
我该怎么做?
请检查这个脚本:
$uri = "https://proto123.hipchat.com/v2/user?auth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
try {
$webResponse = Invoke-RestMethod -uri $uri -ContentType "application/json"
} catch {
$webResponse = $_.Exception.Response
}
if ($webResponse) {
Write-Debug "Output result"
$webResponseIDList = @() # Defining array for collecting the ID's
foreach ($webResponseID in $webResponse) {
$webResponseIDList += [PSCustomObject] @{
id = $webResponseID.id
} # End of ID's Array
$id = $webResponseID.id
Write-Host "User ID is : $id" + $webResponseIDList `r`n
$uri = "https://proto123.hipchat.com/v2/user/$id?auth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$webResponseID = Invoke-RestMethod -uri $uri -ContentType "application/json"
Write-Host "User ID are :" + $webResponseID.id `r`n
Write-Output "User ID are :" + $webResponseID.id `r`n
}
} else {
Write-Debug "No results were returned"
}
我没有在 PowerShell 中获得输出。
改变
foreach ($webResponseID in $webResponse) {
...
}
至
foreach ($webResponseID in $webResponse.items) {
...
}