I have a problem to iterate a object. After Deserialize a json, I have some data like a object[]. But I only need some values.
this is that part of my code:
object[] datos;
StreamReader r = new StreamReader( Server.MapPath( "~/EmpresasLista.json" ) ); // later will come from API
string jsonString = r.ReadToEnd();
JavaScriptSerializer js = new JavaScriptSerializer();
dynamic respObject = js.Deserialize<dynamic>( jsonString );
datos = respObject["Datos"]; // this is data what I need
for ( int i= 0; i <= datos.Length; i++)
{
//System.Diagnostics.Debug.Write( "Objeto json: " + d["Nombre"].ToString() );
System.Diagnostics.Debug.Write( "Objeto json " + i + ":" + datos.ElementAt(i).ToString() );
}
this is part of json file (I retrieve much more with more properties, but bassically is this)
{
"Estado": "OK",
"Datos": [
{
"Numero": 61321,
"Nombre": null,
"CodigoAgenteVenta": 36,
"AgenteVenta": null,
"Actividad": null,
"CodigoActividad": 40,
"RazonSocial": "UNIDAD EDUCATIVA SAN LUIS GONZAGA",
"Ruc": "1791386906001",
},
{
"Numero": 61327,
"Nombre": null,
"CodigoAgenteVenta": 148,
"AgenteVenta": null,
"Actividad": null,
"CodigoActividad": 40,
"RazonSocial": "FUNDACION EDUCACIONAL ALBERTO EINSTEIN",
"Ruc": "1791376323001",
},
{
"Numero": 61365,
"Nombre": null,
"CodigoAgenteVenta": 57679,
"AgenteVenta": null,
"Actividad": null,
"CodigoActividad": 46,
"RazonSocial": "TATASOLUTION CENTER S.A.",
"Ruc": "1792072328001",
},
{
"Numero": 5010098,
"Nombre": null,
"CodigoAgenteVenta": 36,
"AgenteVenta": null,
"Actividad": null,
"CodigoActividad": 46,
"RazonSocial": "MOORE STEPHENS & ASOCIADOS CIA LTDA",
"Ruc": "0992684038001",
},
{
"Numero": 5010113,
"Nombre": null,
"CodigoAgenteVenta": 58609,
"AgenteVenta": null,
"Actividad": null,
"CodigoActividad": 46,
"RazonSocial": "DISMEDSA CIA. LTDA.",
"Ruc": "0991473998001",
},
{
"Numero": 5010114,
"Nombre": null,
"CodigoAgenteVenta": 58609,
"AgenteVenta": null,
"Actividad": null,
"CodigoActividad": 46,
"RazonSocial": "CORPORACION CELESTE CIA. LTDA. CORPACEL",
"Ruc": "0992426357001",
}
],
"Mensajes": []
}
How can I get for example Ruc value or Nombre Value? Just need a few properties for sending to another application.
My problem is that I retrieve the data in an object[] with deserialization, as you can see in the screen captures and I want to iterate that object to obtain the values.
Please, I hope you can help me.
Best Regards.