I have the following JSON:
{
"-LY2_Np3-jTOC9T0-Xzb": {
"Descripcion": "Se realizo una factura(p) en tienda: 3 por el usuario: ARMANDO",
"Fecha": "2019-02-06",
"Hora": "10:13:01 AM",
"Monto": "10763.5",
"Tipo": "Transaccion"
},
"-LY2j1Fbl195pooEich8": {
"Descripcion": "Se realizo una factura(f) en tienda: 3 por el usuario: ARMANDO",
"Fecha": "2019-02-06",
"Hora": "10:55:10 AM",
"Monto": "26900",
"Tipo": "Transaccion"
},
"-LY2jyHCM1DtZAxdxt7W": {
"Descripcion": "Se realizo una factura(p) en tienda: 3 por el usuario: ARMANDO",
"Fecha": "2019-02-06",
"Hora": "10:59:16 AM",
"Monto": "29830",
"Tipo": "Transaccion"
},
"-LY2nQxcbMGO0oP5vmOM": {
"Descripcion": "Se realizo una factura(p) en tienda: 3 por el usuario: ARMANDO",
"Fecha": "2019-02-06",
"Hora": "11:14:24 AM",
"Monto": "9830",
"Tipo": "Transaccion"
}
}
As you can see the id is dynamic. How can I deserialize this file in C#?
In these cases you can deserialize using a
Dictionary
. Create a class for the itemsAnd then you deserialize like this:
Each of the dictionary keys are the ids, for example you can get the first element like this:
Here
How to convert a JObject to List<>
the same problem was raised, where it has dynamic properties.
Basically you define the class
And then you can use
JObject.Parse()