0

This might be a simple question, but I can't find the solution to it.

I'm doing a parse with newtonsoft from a Json string, with multiple depth levels:

{"lineage":
   {"type": "raw",
   "source": "OPC_UA",
   "self":
      {"uuid":"73dd8608-29b2-44ed-a924-b3d3ba3d0345"}},
"data":
   {"OPC_UA": 
      {"Sensor1":false,
       "Sensor2":false,
      "Sensor3":false,
      "Sensor4":false,
      "Sensor5":false,
      "Snelheid":0}}}

Now my question is, how do I get a value from a lower level than lineage or data? trough the get value method? for example I tried getvalue("source"), but this returned nothing.

dbc
  • 104,963
  • 20
  • 228
  • 340
  • 1
    `string source = (string)jObj.SelectToken("lineage.source");` – Brian Rogers May 17 '20 at 18:40
  • 1
    You can use `SelectToken()`, see [What is the JSON.NET equivalent of XML's XPath, SelectNodes, SelectSingleNode?](https://stackoverflow.com/q/1698175/3744182). Or you can chain together multiple index operations using the null conditional operator, see [Json.NET get nested jToken value](https://stackoverflow.com/a/42300875/3744182). In fact I think this is a duplicate of those two, agree? – dbc May 17 '20 at 18:40
  • Example of chaining together: `(string)jObj?["lineage"]?["source"]` – dbc May 17 '20 at 20:24

0 Answers0