如何将数组的内容存储到 powershell 中的 json 文件
How do I store the contents of an array to a json file in powershell
我想将数组的内容保存到 .json file.The 数组中有一些字典。我试过了
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
我想将数组的内容保存到 .json file.The 数组中有一些字典。我试过了
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