Deserialize JSON with json.NET to C # dynamics

I have the following problem: I have a json file similar to this

{ "Path": { "FirstPath": "/1/2/text()" } } 

If I parse this JSON file with Newtonsoft, like this

  dynamic dyn = JObject.Parse(json); 

or

 dynamic dyn = JsonConvert.DeserializeObject(json); 

I get a dynamic object to use as

 dyn.Path.FirstPath.Value 

How can I get rid of value? All my objects in JSON are ultimately a string. I do not want to always write ".Value" at the end, if it is not necessary.

+7
json c #
source share
1 answer

I tested this with Newtonsoft 8.0.2 and it works great.

  dynamic dyn = JObject.Parse(json); string value = dyn.Path.FirstPath; 

The value should be equal to /1/2/text() .

+11
source share

All Articles