CSharp · Console
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
string json = @"{
""ErrorCode"":""""
,""ErrorMessage"":""""
,""AppointmentReasonList"":[
{
""ClassCode"":""851""
,""ClassDescription"":""newpat""
,""Active"":true
,""IsPatientRelated"":true
,""ReasonCodeList"":[
{
""Code"":""851""
,""Description"":""Emergency New Patient Visit""
,""Duration"":15
,""Active"":true
}
,{
""Code"":""BH NEW""
,""Description"":""BH NEW""
,""Duration"":15
,""Active"":true
}
]
}
,{
""ClassCode"":""ANE""
,""ClassDescription"":""Anesthesia""
,""Active"":true
,""IsPatientRelated"":true
,""ReasonCodeList"":[
{
""Code"":""123456""
,""Description"":""This is only a test""
,""Duration"":15
,""Active"":true
}
]
}
]
}";
var root = JsonConvert.DeserializeObject<RootObject>(json);
foreach (var appointmentReason in root.AppointmentReasonList)
{
foreach (var reasonCode in appointmentReason.ReasonCodeList)
{
Console.WriteLine("Code: " + reasonCode.Code + "; Description " + reasonCode.Description);
}
}
}
}
public class ReasonCodeList
{
public string Code { get; set; }
public string Description { get; set; }
public int Duration { get; set; }
public bool Active { get; set; }
}
public class AppointmentReasonList
{
public string ClassCode { get; set; }
public string ClassDescription { get; set; }
public bool Active { get; set; }
public bool IsPatientRelated { get; set; }
public List<ReasonCodeList> ReasonCodeList { get; set; }
}
public class RootObject
{
public string ErrorCode { get; set; }
public string ErrorMessage { get; set; }
public List<AppointmentReasonList> AppointmentReasonList { get; set; }
}