如何检查两个JSON对象是否相等? [英] How do I check two JSON objects are equal?
本文介绍了如何检查两个JSON对象是否相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图发现两个JSON字符串是否相等.
I'm trying to discover if two JSON strings are equal.
这是我以前尝试过的
var obj1 = Json.Decode("{\"ValueA\":1,\"ValueB\":2}")
var obj2 = Json.Decode("{\"ValueB\":2,\"ValueA\":1}")
// But then there seems to be no way to compare the two objects?
当然,必须存在一种优雅的简单方法来实现我认为是常见的任务?
Surely there must exist an elegant simple way to what I thought would be a common task?
推荐答案
另一种比较json的方法-将JSON与JToken.DeepEquals比较
Another way to compare json - Comparing JSON with JToken.DeepEquals
JObject o1 = new JObject
{
{ "Integer", 12345 },
{ "String", "A string" },
{ "Items", new JArray(1, 2) }
};
JObject o2 = new JObject
{
{ "Integer", 12345 },
{ "String", "A string" },
{ "Items", new JArray(1, 2) }
};
Console.WriteLine(JToken.DeepEquals(o1, o2));
这篇关于如何检查两个JSON对象是否相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文