【发布时间】:2018-04-02 17:34:09
【问题描述】:
我有一个关于使用 powershell 从/到 json 转换的问题。我需要一个具有特定格式的 json(用于 REST 调用),但如果我执行 convertfrom-json 和 convertto-json 格式错误,我不知道如何更改它。 这是原始格式:
{
"property-content": [
{
"statKey": "Test|Test1",
"timestamps": [1522678260000],
"values": ["compliant"],
"others": "",
"otherAttributes": ""
}
]
}
如果我做一个 converfrom-json ...然后我改变一些值然后我做一个 convertto-json 格式是没有括号的:
{
"property-content": [
{
"statKey": "Test|Test1",
"timestamps": "1522678260000",
"values": "compliant",
"others": "",
"otherAttributes": ""
}
]
}
谢谢!
【问题讨论】:
-
我没有对 json 做很多工作,但我怀疑您需要在 json 中更改新值之前将其强制为数组。
-
方括号表示该值是一个数组。如果 powershell 不将输入解释为数组,则它不会输出带有方括号的 json 文本。一般没关系,你的api有抱怨吗?
-
如果再深入一点,你会注意到单值数组不只是变成了一个值,而且值本身
."property-content"."timestamps"类型也从int64转换为string...
标签: json rest powershell