我使用以下内容填充了一个数组:
forEach ($ip in $ipReturn.IPAddress) {
try {
$jsonObject = Invoke-RestMethod -Method Get -Uri "https://api.weatherchannel/forecast/daily?ip=$ip&days=2&units=I&key=$apiKey" -Headers $header
$jsonDataArray += $jsonObject
}
catch {
$errorTrap = $error[0]
Write-Host "Status Code:" $_.Exception
Write-Host "Status Description:" $_.Exception
}
}
我在 PowerShell 的数组中填充了以下数据:
$jsonDataArray | foreach{Write-Host $_}
@{timezone=America/New_York; city_name=Azalea Park; lon=-81.3004; data=System.Object[]; state_code=FL; country_code=US; lat=28.5535}
我需要位于每个数组片段中的数据。特别是:data=System.Object
。
我曾想过使用以下结构:
$foreach (system.object['data'] in $jsonDataArray)
{
//pull and extract all data as string objects and populate those strings into a new array. Search each array string and pull data to create histogram.
}
我已经查看了代码。有谁知道我如何实现这种数据提取?
最佳答案
不要让 data
字段的类型分散您的注意力:)
foreach($jsonData in $jsonDataArray)
{
foreach($data in $jsonData.data)
{
# $data represents each object in the data array
}
}
关于arrays - 在 Powershell 中从数组中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49601347/