I have a json file, where i have to validate a json attribute element value based on another json element attribute value. But if there json elements with the same name. It always takes the last value always instead of parsing the json data fully. Please guide me.
Below the sample json file
{"PLMXML":{"language":"en-us","author":"Developer","date":"2020-05-22","traverseRootRefs":"#id6","Operation":{"id":"id21","subType":"BS4_BaOP","catalogueId":"70700000209604", },"Operation":{"id":"id28","subType":"BS4_BaOP","catalogueId":"70700000209603", },"OperationRevision":{"id":"id6","subType":"BS4_BaOPRevision","masterRef":"#id21","revision":"A1", } }}
And below the code which im trying to use
public void Readjsonfile(string jsondata){ var message = JsonConvert.DeserializeObject<plmxmldatamodel>(jsondata); if (String.Equals(message.PLMXML.traverseRootRefs.Substring(1), message.PLMXML.OperationRevision.id)) { Console.WriteLine("Condtion1"); if (String.Equals(message.PLMXML.OperationRevision.masterRef.Substring(1), message.PLMXML.Operation.id)) { Console.WriteLine("Condition_2"); //Do something based on the condtion } }}public class Operation{ public string id { get; set; } public string subType { get; set; } public string catalogueId { get; set; }}public class OperationRevision{ public string id { get; set; } public string subType { get; set; } public string masterRef { get; set; }}public class PLMXML{ public string language { get; set; } public string author { get; set; } public string date { get; set; } public string traverseRootRefs { get; set; } public Operation Operation { get; set; } public OperationRevision OperationRevision { get; set; }}public class plmxmldatamodel{ public PLMXML PLMXML { get; set; }}
When i try to dedug this in the second if condtion, the value for message.PLMXML.Operation.id is always id28 , because of which second if condition fails. While the first if condition is passed as there is only one message.PLMXML.OperationRevision.id. i wanted behaviour where it would check complete json data and check if message.PLMXML.Operation.id with value id21 is present or not , So my data gets passed. Please kindly guide me here.I am very new to C# here.