Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to deserialize a Json Array into different Object?
    text
    copied!<p>i'm trying to deserialize a json string into a new list on C# using json.net.</p> <p>When i do a direct deserialization i get some attributes as null because i have different objects on my list.</p> <p>So i want to create a "translator" for that task, building generic objects and setting the attributes of my objects.</p> <p>this is my progress..</p> <pre><code>CitasProfesorWeb.JavaService.AgendaWSService service = new JavaService.AgendaWSService(); JsonTextReader reader; private void cargaDatos() { String lista = service.obtenerCitasNuevas(2); reader = new JsonTextReader(new StringReader(lista)); while (reader.Read()) { //here i want to read the attributes or objects } } </code></pre> <p>i have tried using JsonConvert.PopulateObject(reader,cita) but i'm getting an error message saying that i have invalid parameters.</p> <p>--Edit--</p> <p>This is the string that i'm receiving :</p> <pre><code>[{"idCita":6,"fechaSolicitud":"2012/4/20","fechaCita":"2012/4/19","horario":{"idHorario":1,"fechaInicio":"2012/1/16","fechaHoy":1337281297199,"fechaFin":"2012/5/30","nombre":"Enero-Mayo 2012","profesor":{"idProfesor":2, "nombre":"Guillermo", "apellido":"Salazar", "nomUsuario":"g.salazar", "email":"g.salazar@itson.mx", "ubicacion":"LV323", "descripcion":"Profesor Interino"}},"alumno":{"idAlumno":1, "nombre":"Jhonatan", "apellido":"Romero", "nomUsuario":" jromero", "email":"jhonatanromgggggh", "carrera":"LSIA" },"asunto":"asesorias","status":"0","horaCita":"10:0"}, {"idCita":7,"fechaSolicitud":"2012/4/20","fechaCita":"2012/4/27","horario":{"idHorario":1,"fechaInicio":"2012/1/16","fechaHoy":1337281297199,"fechaFin":"2012/5/30","nombre":"Enero-Mayo 2012","profesor":{"idProfesor":2, "nombre":"Guillermo", "apellido":"Salazar", "nomUsuario":"g.salazar", "email":"g.salazar@itson.mx", "ubicacion":"LV323", "descripcion":"Profesor Interino"}},"alumno":{"idAlumno":1, "nombre":"Jhonatan", "apellido":"Romero", "nomUsuario":" jromero", "email":"jhonatanromgggggh", "carrera":"LSIA" },"asunto":"asesorias","status":"0","horaCita":"11:0"}, {"idCita":11,"fechaSolicitud":"2012/4/20","fechaCita":"2012/4/20","horario":{"idHorario":1,"fechaInicio":"2012/1/16","fechaHoy":1337281297199,"fechaFin":"2012/5/30","nombre":"Enero-Mayo 2012","profesor":{"idProfesor":2, "nombre":"Guillermo", "apellido":"Salazar", "nomUsuario":"g.salazar", "email":"g.salazar@itson.mx", "ubicacion":"LV323", "descripcion":"Profesor Interino"}},"alumno":{"idAlumno":1, "nombre":"Jhonatan", "apellido":"Romero", "nomUsuario":" jromero", "email":"jhonatanromgggggh", "carrera":"LSIA" },"asunto":"asesorias","status":"0","horaCita":"17:0"}, {"idCita":12,"fechaSolicitud":"2012/4/27","fechaCita":"2012/5/3","horario":{"idHorario":1,"fechaInicio":"2012/1/16","fechaHoy":1337281297199,"fechaFin":"2012/5/30","nombre":"Enero-Mayo 2012","profesor":{"idProfesor":2, "nombre":"Guillermo", "apellido":"Salazar", "nomUsuario":"g.salazar", "email":"g.salazar@itson.mx", "ubicacion":"LV323", "descripcion":"Profesor Interino"}},"alumno":{"idAlumno":1, "nombre":"Jhonatan", "apellido":"Romero", "nomUsuario":" jromero", "email":"jhonatanromgggggh", "carrera":"LSIA" },"asunto":"tesis","status":"0","horaCita":"12:0"}, {"idCita":15,"fechaSolicitud":"2012/5/11","fechaCita":"2012/4/20","horario":{"idHorario":1,"fechaInicio":"2012/1/16","fechaHoy":1337281297200,"fechaFin":"2012/5/30","nombre":"Enero-Mayo 2012","profesor":{"idProfesor":2, "nombre":"Guillermo", "apellido":"Salazar", "nomUsuario":"g.salazar", "email":"g.salazar@itson.mx", "ubicacion":"LV323", "descripcion":"Profesor Interino"}},"alumno":{"idAlumno":1, "nombre":"Jhonatan", "apellido":"Romero", "nomUsuario":" jromero", "email":"jhonatanromgggggh", "carrera":"LSIA" },"asunto":"Tesis","status":"0","horaCita":"10:0"}] </code></pre> <p>This is my class:</p> <pre><code>public class Cita { Profesor profesor; public Profesor Profesor { get { return profesor; } set { profesor = value; } } Alumno alumno; public Alumno Alumno { get { return alumno; } set { alumno = value; } } DateTime inicioCita; public DateTime InicioCita { get { return inicioCita; } set { inicioCita = value; } } String asunto; public String Asunto { get { return asunto; } set { asunto = value; } } String lugar; public String Lugar { get { return lugar; } set { lugar = value; } } int status; public int Status { get { return status; } set { status = value; } } DateTime fechaSolicitud; public DateTime FechaSolicitud { get { return fechaSolicitud; } set { fechaSolicitud = value; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload