I was working on a section of this code that is grabbing api data. In it I'm taking the json file and reading to a string into json.net to deserialize and put parts of the data into an object class. The way the json reads is a list of Result objects. I have gotten the count from the root method but I am having problems getting data from the list of Result objects.
Object classes
public class Result
{
public string id { get; set; }
public string status { get; set; }
}
public class WarehouseInformation
{
public int count { get; set; }
public List<Result> result { get; set; }
}
orderData is the string of the json file being read in.
{
Console.WriteLine("orderdatatoarray");
WarehouseInformation warehouseInformation = JsonConvert.DeserializeObject<WarehouseInformation>(orderData);
if (warehouseInformation != null)
{
var test = warehouseInformation.count;
string[] orderStringArr = new string[0];
Console.WriteLine(test);
List<Result> idList = new List<Result>();
return orderStringArr;
}
else
{
string[] orderStringArr = new string[0];
return orderStringArr;
}
}
}
The error is: System.NullReferenceException: 'Object reference not set to an instance of an object.'
last is part of the json file I am trying to read from, I doubt this is the issue at fault but I might have missed a way to setup the classes above. json api structure