I have a dynamic JSON which I am deserializing using Newronsoft JSON.
if (string.IsNullOrEmpty(JsonString) == false)
{
DeserializedJson = JsonConvert.DeserializeObject<dynamic>(JsonString);
}
The Json is an array and one of the node is results. I have 2 lists node1 and node2. 2 exact same Json stirngs coming from different sources are populating these lists with items from results node.
public List<object> node1;
public List<object> node2
int Node1TotalResults = Enumerable.Count(Searchers[0].DeserializedJson.Results);
int Node2TotalResults = Enumerable.Count(Searchers[1].DeserializedJson.Results);
for (int i = 0; i <= (Node1TotalResults - 1); i++)
{
node1.Add(Searchers[0].DeserializedJson.Results[i]
}
//Same stuff for node2
Now to Compare, I tried 2 different approaches and none of them see to work. But if I print them manually, both lists look similar. Here is how I compared them:
//1st Method:
if (node1.SequenceEqual(node2))
{
result = true;
}
//2nd Method:
if(object.Equals(node1, node2))
{
result = true;
}
Both of these methods return false. Any thing here that I can do?
Here is the Sample JSON:
"Results": [
{
"MlsCode": "NON-MLS",
"MlsAgentId": "45D7D24E253F46A88458B88891E05A1D",
"UserId": null,
"FirstName": "Eric",
"LastName": "Heal",
"OfficeName": "Nick Salamone Real Estate",
"MlsOfficeId": "62B8C79E0E0E4D63A7EEF2313BAC98DF",
"Phones": [
"3125688028"
]
}
]
I should add, when I convert this json into c# classes and add individual key/item from results array to these lists and compare them using the first method above, it works fine.