How to convert json to object in c #?

3

I have the next json.

{Estudiante:
      {nombre:'paco',
       edad: 20,
       sexo: 'm'},
 Recibos:
       [{folio:'A1213',
         fecha:'10-02-2017',
         total: 56},
         {folio:'A1213',
         fecha:'10-02-2017',
         total: 56}]
 }

To convert student I use the following:

       JObject jObject = JObject.Parse(json);
       JToken objeto = jObject["Estudiante"];
       string nombre = (string) objeto["nombre"];

But I do not know how to perform this process with Receipts.   Thanks.

    
asked by Blidge 09.11.2017 в 21:13
source

1 answer

3

It would be the same, just as it is an array, JArray is used instead of JObject and you read it using a foreach :

JObject jObject = JObject.Parse(json);
JToken objeto = jObject["Estudiante"];
string nombre = (string) objeto["nombre"];      

JArray recibos = (JArray)jObject["Recibos"];    

foreach(JObject item : recibos)
{
    string folio = item.GetValue("filio").ToString();
    //...
}
    
answered by 09.11.2017 / 21:19
source