作者:huanhuan199538 | 来源:互联网 | 2022-12-02 13:30
在上面的例子中,我想从"System.WorkItemType"中获取值"Bug"
运用
$respOnse= Invoke-RestMethod -Url $someUri -Method Get -ContentType "application/json" -Headers $headers
$wit = response.fields.System.WorkItemType
由于点/周期搞砸了,所以不起作用.
在Javascript中有这个问题和答案,但在Powershell中不起作用.
使用正则表达式用下划线替换点似乎太牵强了(我没有让它工作,但使用-match -convertFrom-Json -replace -convertTo-Json所以可能做错了?
所以我的问题很简单:如何从'System.WorkItemType'键中获取'Bug'值?(bug可能是其他字符串...)
1> thom schumac..:
如果您将属性名称放在""
或中''
,您应该能够得到您想要的内容:
$json= @'
{ "id" : 9983,
"rev" : 17,
"fields" :{
"System.AreaPath":"Cloud\\Dev Blue Team",
"System.TeamProject":"Cloud"
}
}
'@
$j = $Json | convertfrom-json
$j.fields."System.AreaPath"
$J.fields.'System.TeamProject'
如果你需要转义双引号,请使用`
严重重音,在PowerShell中称为反引号.
"area path = $($j.fields.`"System.AreaPath`")"