I am getting null values returned when I deserialize a JSON using newtonSoft JSON. Here is my JSON:
{"odata.metadata":"https://graph.abc.com/testapi",
"value":
[{"capabilityStatus":"Enabled",
"consumedUnits":2,
"objectId":"c9992e5ef110_6fd2c87-1e91e994b900",
"prepaidUnits":{"enabled":25,"suspended":0,"warning":0},
"servicePlans":
[{"servicePlanId":"4ccb","servicePlanName":"YAMMER_ENTERPRISE"},
{"servicePlanId":"bea4","servicePlanName":"RMS_S_ENTERPRISE"},
{"servicePlanId":"43de","servicePlanName":"OFFICESUBSCRIPTION"},
{"servicePlanId":"0fea","servicePlanName":"MCOSTANDARD"},
{"servicePlanId":"e95be","servicePlanName":"SHAREPOINTWAC"},
{"servicePlanId":"5dbe","servicePlanName":"SHAREPOINTENTERPRISE"},
{"servicePlanId":"efb8","servicePlanName":"EXCHANGE_S_ENTERPRISE"}],
"skuId":"42f0-b197",
"skuPartNumber":"ENTERPRISEPACK"}]}
and here are my classes:
public class PrepaidUnits
{
public int enabled { get; set; }
public int suspended { get; set; }
public int warning { get; set; }
}
public class ServicePlan
{
public string servicePlanId { get; set; }
public string servicePlanName { get; set; }
}
public class Value
{
public string capabilityStatus { get; set; }
public int consumedUnits { get; set; }
public string objectId { get; set; }
public PrepaidUnits prepaidUnits { get; set; }
public List<ServicePlan> servicePlans { get; set; }
public string skuId { get; set; }
public string skuPartNumber { get; set; }
}
public class Graphdata
{
public string odata_metadata { get; set; }
public List<Value> value { get; set; }
}
So here is the problem, when I deserialize using the following statement, I get returned null values for servicePlanId and servicePlanName. what am I doing wrong here?
var graphAPIDataDeserialized = JsonConvert.DeserializeObject<ServicePlan>(graphResult);
However, when I use the Graphdata class I can see all the values in the JSON response:
var graphAPIDataDeserialized = JsonConvert.DeserializeObject<Graphdata>(graphResult);
Thanks in advance for your help!