作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我下面有使用ConvertFrom-Json
命令解析的JSON文件:
{
"item1": {
"class": "class1",
"price": "price1"
},
"item2": {
"class": "class2",
"price": "price2"
}
}
PSCustomObject
和
item1
的
item2
。它产生以下输出:
item1 item2
----- -----
@{class=class1; price=price1} @{class=class2; price=price2}
name class price
---- ----- -----
item1 class1 price1
item2 class2 price2
最佳答案
在我的同事的代码中找到了解决方案:
$json = Get-Content -Path "<file-path>" | ConvertFrom-Json;
$json.PSObject.Properties | ForEach-Object { [PSCustomObject] @{
name = $_.Name;
class = $_.Value.class;
price = $_.Value.price;
}}
关于powershell - 如何在PowerShell中将PSCustomObject转换为数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59398000/
我是一名优秀的程序员,十分优秀!