0
遞歸循環,我有我的JSON如下通過JSON對象在PowerShell中
{
"cluster": [
{
"id": "cluster1.1",
"color": "blue",
"segment": [
{
"id": "segment1.1",
"color": "green"
}
]
},
{
"id": "cluster1.2",
"color": [
"blue",
"red"
],
"segment": [
{
"id": "segment1.2",
"color": "Yellow"
}
]
},
{
"id": "cluster1.3",
"color": "Orange",
"segment": [
{
"id": "cluster1.3",
"color": "black"
},
{
"id": "cluster1.4",
"color": "Green"
},
{
"id": "cluster1.5",
"color": "red"
}
]
},
{
"id": "cluster1.4",
"color": [
"blue",
"red"
],
"segment": [
{
"id": "cluster1.4",
"color": "red"
},
{
"id": "cluster1.5",
"color": "blue"
},
{
"id": "cluster1.6",
"color": "Yellow"
}
]
}
]
}
我想循環這個遞歸遍歷所有的節點,我得到的內容與下面的代碼如下,但我沒有得到通過所有節點
$jsonData = (Get-Content -FilePath) -join "`n" | ConvertFrom-Json
for($i=0; $i -lt $jsonData.cluster.Length; $i++)
{
$clusterInfo= $ReportingPackage.cluster[$i]
$clusterInfo.Color
}
我需要通過所有段遞歸找到一種方式來循環和顏色
嗨,謝謝當我試圖獲得獨特的顏色與出來重複我不能得到'$ allColors.color |選擇-Unique'你能幫我嗎 – Nithya
1.這是一個不同的問題。 2.確保始終在PowerShell ISE或控制檯中檢查數據的內容,因爲我的第二個示例生成一個不帶'.color'屬性的普通字符串數組:'$ allColors |選擇-unique' – wOxxOm