Im using C# in VS2017. I have a json from where I get data, and this 3 classes:
public class Azar
{
public int id_juego { get; set; }
public string timestamp { get; set; }
public int id_tipojuego { get; set; }
public string fecha { get; set; }
public int? sorteo { get; set; }
public object resultados { get; set; }
public string tipo_juego { get; set; }
public int tipo { get; set; }
}
public class ResultadoQuiniela
{
public string letras { get; set; }
public int[] numeros { get; set; }
}
public class ResultadoTelekino
{
public int sorteo { get; set; }
public int b1 { get; set; }
public int b2 { get; set; }
public int b3 { get; set; }
public int b4 { get; set; }
public int b5 { get; set; }
public int b6 { get; set; }
public int b7 { get; set; }
public int b8 { get; set; }
public int b9 { get; set; }
public int b10 { get; set; }
public int b11 { get; set; }
public int b12 { get; set; }
public int b13 { get; set; }
public int b14 { get; set; }
public int b15 { get; set; }
public int cat1 { get; set; }
public int cat2 { get; set; }
public int cat3 { get; set; }
public int cat4 { get; set; }
public int cat5 { get; set; }
public int cat6 { get; set; }
public int cat7 { get; set; }
public string prm1 { get; set; }
public string prm2 { get; set; }
public string prm3 { get; set; }
public string prm4 { get; set; }
public string prm5 { get; set; }
public string prm6 { get; set; }
public string prm7 { get; set; }
public string pozo { get; set; }
public string ext { get; set; }
}
The Azar->resultados object can be any of the 2 classes, or ResultadoQuiniela or ResultadoTelekino. I don't know which of them is until I parse the json and see the id_tipojuego. Once I know that I do:
if(curAzar.id_tipojuego == 25)
{
ResultadoQuiniela resultados = (ResultadoQuiniela)curAzar.resultados;
}
But I get null results. I see that curAzar (is the result parsed from the json) was every attribute set BUT the resultados object. How can I store that information in a "neutral" way and then cast it to the right object? Declaring it as object and then cast it it doesn't store the value at all.
EDIT: For parsing the json Im using Newtonsoft.Json