如何将数组的内容存储到powershell中的json文件中

如何将数组的内容存储到powershell中的json文件中,powershell,powershell-2.0,powershell-3.0,Powershell,Powershell 2.0,Powershell 3.0,我想将数组的内容保存到一个.json文件中。数组中有一些字典。我试过了 Set-Content -Path 'crl_urls.json' -Value $arrayval -Force JSON文件存储了System.Collections.Hashtable。它没有存储字典的值 那么我该怎么做呢?通过使用ConvertTo-Jsoncmdlet,我能够在Json文件中导出数组的内容。 示例代码: Set-Content -Path 'crl_urls1.json' -Value ($arr

我想将数组的内容保存到一个.json文件中。数组中有一些字典。我试过了

Set-Content -Path 'crl_urls.json' -Value $arrayval -Force
JSON文件存储了
System.Collections.Hashtable
。它没有存储字典的值


那么我该怎么做呢?

通过使用
ConvertTo-Json
cmdlet,我能够在Json文件中导出数组的内容。 示例代码:

Set-Content -Path 'crl_urls1.json' -Value ($arrayval|ConvertTo-Json) -Force

要正确地将内容保存在.json文件中,首先应将数组转换为.json格式。 试试这个:

ConvertTo-Json -InputObject $arrayval | Out-File -FilePath .\crl_urls.json