Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

How to Json Element is present or not using C# (With Newtonsoft NugetPackages)

$
0
0

I have Json file, where i am trying the parse the data of the json file for database update with some data contions, Currently i want to check an particular element exists or not.In my current Json data, Under the Operation Node the accessRef can exist in the file or may not exist completely.So how would check the condtion. Kindly suggest me.

Below is the Json file

{"PLMXML":{"language":"en-us","time":"16:50:15","schemaVersion":"6","author":"Development(-2069033203)","date":"2020-05-22","Header":{"id":"id1","traverseRootRefs":"#id6","transferContext":"CLM"          },"Operation":{"id":"id21","name":"PD_Op2","subType":"BS4_BaOP","accessRefs":"#id18","catalogueId":"70700000209604","ApplicationRef":{"application":"Teamcenter","label":"yDX58d4FIpN8QD","version":"yDX58d4FIpN8QD"             }          }      }} 

Below the Code which i am trying perform

public void Readjsonfile(string jsondata){   var message = JsonConvert.DeserializeObject<plmxmldatamodel>(jsondata);                 Console.WriteLine("RootRef: "+ message.PLMXML.Header.traverseRootRefs);    Console.WriteLine("OccurenceId: "+message.PLMXML.ProductView.Operation.id);// I want to check whtether is accessrefs is present or not inside the Operation element}    //fuction1public class Header{       public string traverseRootRefs { get; set; }    }//fuction2public class Operation{   public string id { get; set; }    public string name { get; set; }    public string subType { get; set; }    public string accessRefs { get; set; }    public string catalogueId { get; set; }}//fuction3public class PLMXML{    public string language { get; set; }    public Header Header { get; set; }    public Operation Operation { get; set; }}//fuction4public class plmxmldatamodel{    public PLMXML PLMXML { get; set; }}

Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>