我正在连接到 REST 服务
$response = Invoke-RestMethod -Uri $URL -Headers $headers -Method POST -Body $body_json -ContentType "application/json"
$response.Outputs
我得到了那种格式的回复
Actual: {
"2017-08-29T14:37:47.137",
"2017-08-30T13:07:09.563",
"2017-08-30T14:41:29.023"
},
Start: {
"2017-08-29T14:36:12.42",
"2017-08-30T12:59:53.05",
"2017-08-30T14:40:45.34"
},
NumScrapsList: {
0,
3,
...
但我想以那种形式拥有它
{
"NumScrapsList":0,
"Actual":"2017-08-29T14:37:47.137",
"Start":"08-29T14:36:12.42"
},
{
"NumScrapsList":3,
"Actual":"2017-08-30T13:07:09.563",
"Start":"2017-08-30T12:59:53.05"
}
在pythonic方法中,我可以这样做(包括“输出”键):
outputs = [dict(zip(resp['Outputs'].keys(), e))
for e in zip(*resp['Outputs'].values())]
pprint(outputs)
但在powershell中我不知道该怎么做。你能把我引向正确的方向吗?
使用来自 Invoke-RestMethod的完整$response.outputs进行编辑
$response.outputs 是
Type : {a, b, c}
Code : {xxx, yyy, eee}
CompletionDate : {1900-01-01T00:00:00, 1900-01-01T00:00:00, 1900-01-01T00:00:00}
OrderQuantity : {30, 30, 3}
NumScraps : {0, 0, 0}
ActualDate : {2021-11-16T15:17:00, 2021-11-16T15:18:00, 1900-01-01T00:00:00}
Status : {WT, FD, RT}
Order : {70000, 30794, 94098}
Sequence : {0300, 0400, 0500}
然后我可以转换为json,输出是:
{
"Type": [
"a",
"b",
"c"
],
"Code": [
"xxx",
"yyy",
"eee"
],
"CompletionDate": [
"1900-01-01T00:00:00",
"1900-01-01T00:00:00",
"1900-01-01T00:00:00"
],
"OrderQuantity": [
30,
30,
3
],
"NumScraps": [
0,
0,
0
],
"ActualDate": [
"2021-11-16T15:17:00",
"2021-11-16T15:18:00",
"1900-01-01T00:00:00"
],
"Status": [
"WT",
"FD",
"RT"
],
"Order": [
"70000",
"30794",
"94098"
],
"Sequence": [
"0300",
"0400",
"0500"
]
}
这就是说waitingforguacamole解决方案即使有点棘手也可以工作(当然,感谢您的帮助!)