Try with this change. This way your C# classes will match the JSON object your are receiving. You should of course extend the Data
class to include the rest of the json fields if they are of interest to you.
public class Response
{
[JsonProperty(Required = Required.Default)]
public string Domain { get; set; }
[JsonProperty(Required = Required.Always)]
public Data Data { get; set; }
}
You will notice that I added the required to AllowNull
for Expiration
+RegistrantEmail
and the Data
property to Always
. If you send null for Data
the deserialization will fail.
public partial class Data
{
[JsonProperty(Required = Required.Default)]
public bool Available { get; set; }
[JsonProperty(Required = Required.AllowNull)]
public object Expiration { get; set; }
[JsonProperty("registrant_email" ,Required = Required.AllowNull)]
public object RegistrantEmail { get; set; }
}
var response = JsonConvert.DeserializeObject<Response>(finishResponse);
Console.WriteLine(response.Data.available);
This answer also considers some of the fields in your serialized json string may be null and thus won't throw exception if that's the case.