我是Power
Shell的新手,并拥有以下代码:
$jsonResponse = @" { "departments":[{"id":81,"department":"Sales"},{"id":61,"department":"IT Support"}] } "@ $myCustomObject = $jsonResponse | ConvertFrom-Json $myCustomObject.departments.department[0] $myCustomObject.departments.department[1]
这允许我访问customObject的元素(从JSON转换).
我需要的是循环对象的能力,以便我可以访问每个元素,即
object_loop { $myCustomObject.departments.department[x] }
其中x是循环增量.
对不起,这是一个愚蠢的问题,但我google了,找不到一个简单的例子.
欢呼任何帮助.
Duncs
解决方法
这是微不足道的
foreach($obj in $myCustomObject.departments) { Write-Host ("Got" + $obj.department) }