arrays - 转换后Powershell缺少数组
问题描述
当我转换一个 powershell 对象时,属性bar
和属性的数组foo
丢失了。我使用以下命令将生成的 json 对象导出到文件:$stackoverflow| ConvertTo-Json | set-content '.\foobar.json'
@stackoverflow = @{
name = "question"
description = "stackoverflow is amazing!"
version = 1.0
myattribute = @(
@{
foo = @("value1")
bar = @("value2")
}
)
}
我希望输出看起来像这样foo = ["value1"]
and bar = ["value2]
,但 json 文件中的实际输出是foo = "value1"
and bar = "value2"
。
谢谢您的帮助。
解决方案
通过引用版本号并从 myattribute 中删除 splat,我得到了它的预期工作:
$stackoverflow = @{
name = "question"
description = "stackoverflow is amazing!"
version = "1.0"
myattribute = (
@{
foo = @("value1")
bar = @("value2")
}
)
}
从输出$stackoverflow | ConvertTo-Json
{
"myattribute": {
"bar": [
"value2"
],
"foo": [
"value1"
]
},
"description": "stackoverflow is amazing!",
"name": "question",
"version": "1.0"
}
推荐阅读
- docker - 在 docker 镜像中执行命令以启动 solr exporter
- svg - 在 SVG 路径动画中为 SVG 设置动画
- powershell - 使用 new-item 创建文件夹偶尔会在 Powershell 中引发错误
- python - PyQt5 QTreeView 在检查子节点时自动折叠
- objective-c - 为什么我无法关闭 Touch ID 提示?
- android - 我以为 ANDROID_ID 永远不会改变,但我错了
- php - exec 返回 sh:-c:第 0 行:意外标记 `(' 附近的语法错误
- php - 禁用目录浏览 wamp
- python - 如何在启动 gunicorn 之前设置 Django 服务器状态
- python - 如何在 Maya 中添加事件过滤器