【发布时间】:2022-01-23 10:49:49
【问题描述】:
我正在使用以下代码在 PowerShell 中迭代 JSON 对象
$awsFileResponse = '{
"commitId":"opb274750f582ik",
"blobId":"io6956a1a967243514e194lk54b86",
"filePath":"PowershellScript.ps1",
"fileMode":"NORMAL",
"fileSize":5755,
"fileContent":"7"
}'
foreach($KeyParam in $awsFileResponse)
{
Write-Host 'Ashish'
Write-Host $KeyParam
Write-Host $KeyParam.NAME
Write-Host $KeyParam.VALUE
if($KeyParam.NAME -eq 'fileContent')
{
$fileContentResponse = $KeyParam.VALUE
Write-Host $fileContentResponse
}
}
我没有得到我正在寻找的确切输出。
- 以下行没有打印任何内容 写主机 $KeyParam 写入主机 $KeyParam.NAME 写入主机 $KeyParam.VALUE
- 如果条件不往里面走
【问题讨论】: