Tour Json taking part of the values

0

I have this example of Json's structure

[
  {
    "idgoOperacion": 256,
    "Destino": "Actividades Comunitarias",
    "Tipo de Solicitante": "-",
    "Superficie Otorgada": "",
    "Lugar de Firma": "",
    "Fecha de Firma": ""
  },
  {
    "idgoOperacion": 263,
    "Destino": null,
    "Tipo de Solicitante": null,
    "Superficie Otorgada": null,
    "Lugar de Firma": null,
    "Fecha de Firma": null
  },
  {
    "idgoOperacion": 266,
    "Destino": "Cultura",
    "Tipo de Solicitante": "Civil",
    "Superficie Otorgada": "17",
    "Lugar de Firma": "",
    "Fecha de Firma": "21/06/2015"
  },
  {
    "idgoOperacion": 270,
    "Destino": null,
    "Tipo de Solicitante": null,
    "Superficie Otorgada": valor,
    "Lugar de Firma": "",
    "Fecha de Firma": null
  },
  {
    "idgoOperacion": 273,
    "Destino": null,
    "Tipo de Solicitante": null,
    "Superficie Otorgada": null,
    "Lugar de Firma": null,
    "Fecha de Firma": null
  },
  {
    "idgoOperacion": 274,
    "Destino": null,
    "Tipo de Solicitante": null,
    "Superficie Otorgada": valor,
    "Lugar de Firma": valor,
    "Fecha de Firma": valor
  }]

and I have a table with two fields, idgoOperacion, Json.

I need to save the json in the following way for each operation number and so on

idgoOperacion = 256
Json = {"idgoOperacion": 256,"Destino": "Actividades Comunitarias",     
         "Tipo de Solicitante": "-","Superficie Otorgada": "","Lugar de 
         Firma": "","Fecha de Firma": ""}

and so on.

Try to get the value of the Json in the following way but do not manage to go through the complete json and get the value of idgoOperacion.

JArray jsonPreservar = JArray.Parse(jsonText);
dynamic data = JObject.Parse(jsonPreservar[0].ToString());
    
asked by Sebastian 01.03.2018 в 15:12
source

2 answers

0

You must go through the entire array, so you can get all the values of the properties

JArray jsonPreservar = JArray.Parse(jsonText);
foreach (JObject jsonOperaciones in jsonPreservar.Children<JObject>())
{
    //Aqui para poder identificar las propiedades y sus valores
    /*foreach (JProperty jsonOPropiedades in jsonOperaciones.Properties())
    {
        string propiedad = jsonOPropiedades.Name;
        if (propiedad.Equals("idgoOperacion"))
        {
            var idgoOperacion = Convert.ToInt32(jsonOPropiedades.Value);
        }
    }*/
    //Aqui puedes acceder al objeto y obtener sus valores
    var idgoOperacion = Convert.ToInt32(jsonOperaciones["idgoOperacion"]);

}
    
answered by 01.03.2018 / 15:41
source
0

It is not necessary to use dynamic since it returns a type JObject and from there you need to obtain idgoOperacion of your object in the json

which

JObject data = JObject.Parse(jsonPreservar[0].ToString());
var id = Convert.ToInt32(data["idgoOperacion"]);
    
answered by 01.03.2018 в 15:32