Hi i am not able to bind data in C# class fields.. getting error "Object reference not set to an instance of an object". this is my C# Class as below:
public partial class AccessCodeReqBody
{
[JsonProperty("scenarioKey")]
public string ScenarioKey { get; set; }
[JsonProperty("destinations")]
public Destination[] Destinations { get; set; }
[JsonProperty("whatsApp")]
public WhatsApp WhatsApp { get; set; }
}
public partial class Destination
{
[JsonProperty("to")]
public To To { get; set; }
}
public partial class To
{
[JsonProperty("phoneNumber")]
public string PhoneNumber { get; set; }
}
public partial class WhatsApp
{
[JsonProperty("templateName")]
public string TemplateName { get; set; }
[JsonProperty("templateData")]
public string[] TemplateData { get; set; }
[JsonProperty("language")]
public string Language { get; set; }
}
& the request json as below:
{
"scenarioKey":"696BDB51C0ACF9E65B86D3E1D08A0084",
"destinations":[
{
"to":{
"phoneNumber":"919910666888"
}
}
],
"whatsApp":{
"templateName":"access_code",
"templateData":[
"Jennifer",
"Demo",
"123456"
],
"language":"en"
}
}
& the code for bind data in c# class as below where i am getting error on binding Phone number & template name :
AccessCodeReqBody reqbody = new AccessCodeReqBody();
reqbody.ScenarioKey = "51F5865AE296FAE86614EED";
reqbody.Destinations.To.PhoneNumber = text1;
reqbody.WhatsApp.TemplateName = "access_code";
reqbody.WhatsApp.Language = "en";
reqbody.WhatsApp.TemplateData = GetData(text2.ToString());
Thanks in Advance.