You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell对比两个JSON文件差异的代码故障求助

PowerShell对比两个JSON文件差异的代码故障求助

各位好,我现在尝试用下面这段PowerShell代码来对比两个JSON文件的差异,但看起来没起作用。另外我还需要只要内容有变化就显示出来,麻烦帮忙看看哪里有问题,谢谢!

$filePath1 = "C:\Rules1.json"

$filePath2 = "C:\Rules2.json"

$contents1 = Get-Content $filePath1 -Raw | ConvertFrom-Json

$contents2 = Get-Content $filePath2 -Raw | ConvertFrom-Json

$differences = Compare-Object $contents1 $contents2 -Property (Get-Member -InputObject $contents1 -MemberType NoteProperty).Name

foreach ($difference in $differences) {

if ($difference.SideIndicator -eq "<=") {

$difference.InputObject | Select-Object -Property $difference.PropertyName | ConvertTo-Json

}

elseif ($difference.SideIndicator -eq "=>") {

$difference.InputObject | Select-Object -Property $difference.PropertyName | ConvertTo-Json

}
}

备注:内容来源于stack exchange,提问作者user3675738

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 13:27:57