在C#中使用newtonsoft查找并返回JSON差异? [英] Find and return JSON differences using newtonsoft in C#?

查看:352
本文介绍了在C#中使用newtonsoft查找并返回JSON差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取使用Newtonsoft进行比较时不匹配的JSON部分的列表.

I'd like to get a list of the JSON parts that don't match when doing a comparison using Newtonsoft.

我有比较的这段代码:

JObject xpctJSON = JObject.Parse(expectedJSON);
JObject actJSON = JObject.Parse(actualJSON);

bool res = JToken.DeepEquals(xpctJSON, actJSON);

但是找不到返回差异值的任何东西.

But can't find anything that returns the diff's.

推荐答案

仅用于帮助将来的查询.我遇到了一个很好的json diff工具.对于json结构的diff/patch,它可以完美地工作:

Just to help future queries. There's a nice json diff tool I came across. It works flawlessly for diff/patch of json structures:

jsondiffpatch.net 还有一个nuget包.

jsondiffpatch.net There's also a nuget package for it.

用法很简单.

var jdp = new JsonDiffPatch();
JToken diffResult = jdp.Diff(leftJson, rightJson);

这篇关于在C#中使用newtonsoft查找并返回JSON差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆