Ошибка Restsharp :предоставление null из результата.data
I'm trying to fetch the data from rest api but getting null from the result.data request4.AddHeader("Content-Type", "application/json"); request4.AddHeader("Authorization", "Bearer " + mytoken); request4.AddParameter("application/json", "{ \"active\": true }", ParameterType.RequestBody); var result = client4.Execute<List<RootObject>>(request4);//getting nullexcception here //Console.WriteLine(result); //Console.ReadKey(); foreach (var i in result.Data) { foreach (var j in i.sales_offices) { Console.WriteLine(j.state); } } } public class SalesOffice { public bool active { get; set; } public string _id { get; set; } public string name { get; set; } public string state { get; set; } } public class RootObject { public bool success { get; set; } public string message { get; set; } public List<SalesOffice> sales_offices { get; set; } } and from json I'm getting this result { "success": true, "message": "Gtm Cities loaded successfully!", "sales_offices": [ { "active": true, "_id": "XXXXX5cb57542ed50d82730d7661d", "name": "UAXXS", "state": "AXXX.P" } Please help me as it is showing no issue in the code
Что я уже пробовал:
<pre>I'm trying to fetch the data from rest api but getting null from the result.data request4.AddHeader("Content-Type", "application/json"); request4.AddHeader("Authorization", "Bearer " + mytoken); request4.AddParameter("application/json", "{ \"active\": true }", ParameterType.RequestBody); var result = client4.Execute<List<RootObject>>(request4);//getting nullexcception here //Console.WriteLine(result); //Console.ReadKey(); foreach (var i in result.Data) { foreach (var j in i.sales_offices) { Console.WriteLine(j.state); } } } public class SalesOffice { public bool active { get; set; } public string _id { get; set; } public string name { get; set; } public string state { get; set; } } public class RootObject { public bool success { get; set; } public string message { get; set; } public List<SalesOffice> sales_offices { get; set; } } and from json I'm getting this result { "success": true, "message": "Gtm Cities loaded successfully!", "sales_offices": [ { "active": true, "_id": "XXXXX5cb57542ed50d82730d7661d", "name": "UAXXS", "state": "AXXX.P" } Please help me as it is showing no issue in the code
Richard MacCutchan
Используйте свой отладчик, чтобы увидеть, какая ссылка вызывает исключение.