0

I have the following JObject:

jObject = {
  "abertura": "09/06/2017",
  "situacao": "ATIVA",
  "tipo": "MATRIZ",
  "nome": "11CARE SERVICOS DE SAUDE LTDA",
  "fantasia": "11CARE",
  "porte": "EMPRESA DE PEQUENO PORTE",
  "natureza_juridica": "206-2 - Sociedade Empresária Limitada",
  "qsa": [{
    "nome": "SANTA RITA PARTICIPACOES E INVESTIMENTOS LTDA",
    "qual": "22-Sócio",
    "nome_rep_legal": "PRISCILA CARLA ALBANIT",
    "qual_rep_legal": "05-Administrador"
  }, {
    "nome": "PRISCILA CARLA ALBANIT",
    "qual": "05-Administrador"
  }]
}

I can get values from the properties like this:

var abertura = jObject.GetValue("abertura").ToString()

but how can I get the value from a nested property, I want to set the value from property "nome" inside "qsa" in a new variable, I've tried the following:

var nome = jObject.GetValue("qsa").GetValue("nome")

but it does not work, anyone can help?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • You can use `SelectTokens` as shown in [JSON.NET JObject - how do I get value from this nested JSON structure](https://stackoverflow.com/q/40538001/3744182) Or you can chain indexers as shown in [Json.NET get nested jToken value](https://stackoverflow.com/a/42300875/3744182). In fact this looks like a duplicate of those two, agree? – dbc Nov 10 '21 at 18:00
  • 1
    `qsa` is a `JArray` so you need to iterate through it first. Is there any reason you are using `JToken` anyway, why not use real classes with properties? – Charlieface Nov 10 '21 at 20:41
  • yes, agreed, I solved my problem using index, in fact I realized that I will just need the first index of the list , thank you guys – wrafanunes Nov 18 '21 at 17:35

0 Answers0