I have the following response structure which will be serialized following an API call.
public class Details
{
public string firstName { get; set; }
}
public class Result
{
public int maxTry { get; set; }
public int minTry { get; set; }
public List<Details> aggr { get; set; }
public List<string> features { get; set; }
public string zone { get; set; }
}
[Serializable]
public class Root
{
public List<Result> result { get; set; }
}
I have the following array of objects which is an API response.
"result": [
{
“maxTry: 17,
"minTry”: 10,
"details": [
{
“firstName”: “Sam”,
},
{
"firstName”: ”Julio”,
}
],
"aggr": [
“Abc”,
],
"zone": “D3”
},
{
"aggr": [
"Abc",
],
"zone": “C3”
},
{
"aggr": [
"Abc",
],
"zone": “B2”
},
]
}
The problem is even though some objects does not have maxTry and minTry property in the response, when I deserialize the response as follows,
var jobject = JsonConvert.DeserializeObject<Root>(res);
I am still getting the output with maxTry and minTry defaulted to 0. Can this be instead defaulted to null