【发布时间】:2019-03-18 03:17:06
【问题描述】:
在上面的例子中,我想从“System.WorkItemType”中获取值“Bug”
使用
$response = Invoke-RestMethod -Url $someUri -Method Get -ContentType "application/json" -Headers $headers
$wit = response.fields.System.WorkItemType
由于点/句点搞砸了,所以不起作用。
在 javascript 中有这个 question and answer 但在 Powershell 中不起作用。
使用正则表达式用下划线替换点似乎太牵强了(我没有让它工作,但使用了 -match -convertFrom-Json -replace -convertTo-Json 所以可能做错了吗?
所以我的问题很简单:如何从“System.WorkItemType”键中获取“Bug”值? (bug可能是其他字符串...)
【问题讨论】:
-
您可以使用引号,以便按字面意思解析,试试
$wit = response.fields.'System.WorkItemType'或$wit = response.fields."System.WorkItemType"(两者都应该工作)。 -
成功了!非常感谢!
标签: json powershell jsonpath