I am trying to do the following:
Code:
{
"name": "Bob Barker",
"devName": "InformationServices",
"ReturnedData": [{
"level_heading": "blah1",
"DeliverBestMedicalValue": "blah2",
"level_question": "blah3"
}]
}
I can add the **name** and **devName** just fine but I am unsure on how to go about adding the **ReturnedData** part of the array so that it will return as the layout above?
Example code I am using (CLASS):
Code:
public class febRecords
{
[JsonObject]
public class theOutput
{
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "devName")]
public string DevName { get; set; }
[JsonProperty(PropertyName = "ReturnedData")]
public List<ReturnedData> ReturnedData { get; set; }
}
[JsonObject]
public class ReturnedData
{
[JsonProperty(PropertyName = "level_heading")]
public string level_heading { get; set; }
[JsonProperty(PropertyName = "level_question")]
public string level_question { get; set; }
[JsonProperty(PropertyName = "level_1_text")]
public string level_1_text { get; set; }
[JsonProperty(PropertyName = "level_1_status")]
public string level_1_status { get; set; }
[JsonProperty(PropertyName = "level_1_date")]
public string level_1_date { get; set; }
[JsonProperty(PropertyName = "level_1_dd")]
public string level_1_dd { get; set; }
}
And the c#:
Code:
febRecords.RootObject febRecordsData = JsonConvert.DeserializeObject<febRecords.RootObject>(serverResponse);
febRecords.theOutput febFormData = new febRecords.theOutput();
febFormData.ReturnedData.Add(new febRecords.ReturnedData() {
level_heading = headings[x],
level_question = questions[x],
level_1_text = _tmplevelTotal[0],
level_1_status = _tmplevelTotal[1],
level_1_date = _tmplevelTotal[2],
level_1_dd = _tmplevelTotal[3]
});
totalCount += 1;
When I try doing the above I get an error on the febFormData.ReturnedData.Add(...); part stating:
Object reference not set to an instance of an object.
Any help would be great!