我收到“ System.NullReferenceException:'对象引用未设置为对象的实例。”响应返回1个或多个空值时出错,否则效果很好。处理该异常的最佳方法是什么,以便程序继续执行?
var client = new RestClient("https://www.edsm.net/api-v1/system");
var request = new RestRequest("resource/");
request.AddParameter("systemName", "1 Ceti");
request.AddParameter("showInformation", "1");
var response = client.Post<RootObject>(request);
var all = response.Data.information.allegiance;
var fact = response.Data.information.faction
var gov = response.Data.information.government;
var pop = response.Data.information.population;
Console.WriteLine(all);
Console.WriteLine(fact);
Console.WriteLine(gov);
Console.WriteLine(pop);