I want to deserialize a JSON that was given to me from a DB
That's my Dto
public class filiali {
public cliente cli { get; set; }
public int fil { get; set; }
public string nom { get; set; }
public int km { get; set; }
public decimal ore { get; set; }
}
// filiale singola
public class FilialeDto {
public filiali filiali { get; set; }
}
// lista di filiali
public class ListaFilialiDto {
public List<filiali> filiali { get; set; }
}
My Function
private static ListaFilialiDto ProcessFiliali() {
ListaFilialiDto filialeDto = null;
try {
var jsonString = client.GetStringAsync("my service").Result;
filialeDto = JsonConvert.DeserializeObject<ListaFilialiDto>(jsonString);
} catch (Exception ex) {
logger.Error(ex, "Errore chiamata Servizio Filiali");
}
return filialeDto;
}
my json
{"filiali":[{"cli":1,"fil":1,"nom":"Tizio SPA","km":0,"ore":0.00}]}
the problem's that my object "filialeDto" is null and I get the following:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
>(jsonString) and return the result and see if its null
– nalnpir Jun 13 '19 at 14:05