我正在寻找在 azure runbook 上使用 powershell 运行解析 JSON 响应。,以下是我的代码。
$servicePrincipalConnection=Get-AutomationConnection -Name "AzureRunAsConnection"
Connect-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint | Write-Verbose
$uri = 'https://nseindia.com//emerge/homepage/smeNormalMktStatus.json'
$result = Invoke-WebRequest -Uri $uri -UseBasicParsing
Write-Output $result
$result = $result.Content
Write-Output $result
Write-Output $result.NormalMktStatus
Write-Output 'saranaraj kumar'
# Stop-AzStreamAnalyticsJob -Name SQLCDCProcessor -ResourceGroupName RealTimeAnalytics
以下是我的 JSON 响应
StatusCode : 200
StatusDescription : OK
Content : {"NormalMktStatus":"open"}
RawContent : HTTP/1.1 200 OK
X-FRAME-OPTIONS: SAMEORIGIN
Pragma: no-cache
Connection: keep-alive
Content-Length: 26
Cache-Control: max-age=0, no-cache, no-store
Content-Type: application/json
Date: Fri, 27 ...
Forms :
Headers : {[X-FRAME-OPTIONS, SAMEORIGIN], [Pragma, no-cache], [Connection, keep-alive], [Content-Length,
26]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml :
RawContentLength : 26
{"NormalMktStatus":"open"}
saranaraj kumar
从电源我得到上面的 JSOn 响应,我可以读取 response.content 包含 {"NormalMktStatus":"open"}
但如果我正在使用response.content.normalMKTstatus
我得到空白空间。如何解决?而且我想用电源外壳做if-else条件
if(response.content.normalMKTstatus -eq 'open')
{
write-output true
}
else
{
write-output false
}