【发布时间】:2021-11-24 23:02:09
【问题描述】:
目前我正在编写一个从数组中删除然后保存到数据库的函数。当我编写输出时,它不会在文件周围放置包装器(This -> [])。这使得 json 文件不可读。想知道我是否遗漏了什么
$ArrayIndex = $script:jsonDB.username.IndexOf($UserNametextBox.text)
$script:jsonDB = $script:jsonDB | Where-Object{$_ -ne $script:jsonDB[$ArrayIndex]}
$script:jsonDB | ConvertTo-Json -Depth $ArrayIndex -Compress|
Set-Content C:\Support\HardwareCollection.json
$script:TableData = New-Object System.Collections.ArrayList
$script:TableData.AddRange($script:jsonDB)
$script:datagridview.DataBindings.DefaultDataSourceUpdateMode = 0
$script:datagridview.DataSource= $script:TableData
$script:datagridview.Refresh
这是工作数据库的副本
[{"Date":"09/30/2021 10:19:34 -05:00","Username":"Username1000"}]
这是保存不可读的 json 文件时的样子
{"Date":"09/30/2021 10:19:34 -05:00","Username":"Username1000"}
非常感谢大家!!!
【问题讨论】:
标签: json database powershell