【发布时间】:2018-11-26 22:00:07
【问题描述】:
我在 PowerShell 中使用这样的哈希表:
当我将其转换为 JSON 时,请注意“oranges”键不包含括号:
当我通过执行以下操作创建哈希表时,我试图适应这一点:
foreach ($Group in ($input | Group fruit)) {
if ($Group.Count -eq 1) {
$hashtable[$Group.Name] = "{" + ($Group.Group | Select -Expand number) + "}"
} else {
$hashtable[$Group.Name] = ($Group.Group | Select -Expand number)
}
}
当我将它作为哈希表输出时看起来不错,但是当我转换为 JSON 时,我得到了这个:
我正在尝试将单个项目也包含在 [] 中。我在这里发现了一些东西,其中之一把我带到了这里:
https://superuser.com/questions/414650/why-does-powershell-silently-convert-a-string-array-with-one-item-to-a-string
但是当它只包含一个项目时,我不知道如何只定位那个键。
【问题讨论】:
标签: json powershell