arrays - 在 Powershell 中从数组中提取数据

标签 arrays powershell sorting

我使用以下内容填充了一个数组:

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/

相关文章:

c++ - `std::sort` 内部使用了什么魔法让它更快?

c - 关于C中指针和数组的问题

使用 glob 排除 index.php 的 PHP 代码

powershell - 如何使用 Powershell 更改文件的属性?

Powershell,OOP,为什么返回$false不退出类方法

powershell - 用PowerShell递归替换符号

c++ - 基数排序算法说明

c# - 如何检查 int[] 是否只包含某些数字?

javascript - 如何使用谷歌脚本覆盖具有相似名称和数据的现有谷歌工作表?

运行该程序时需要常量表达式错误