You're biggest problems are with the
AppointmentReasonList
and
ReasonCodeList
classes. In your JSON document, these are represented as collections. However, since both classes simply implement
IEnumerable{T}
, there is no way the de-serializer can add elements to the collection.
Consider either inheriting directly from the
List{T}
class or implementing
ICollection{T}
or
IList{T}
.
In my experiments, both of these resolved the issue you note.
Separately, one of your
foreach
loops is not valid,
AppointmentReason
is not enumerable, you probably mean
ApptReason.ReasonCodeList
.
So, just to clarify, below are the recommended fixes. Each has been tested in VS 2017 (with the call to the missing AddInterfaceRMReasonCode commented out).
This is the recommended fix to the
foreach
loop:
foreach (AppointmentReason ApptReason in jarray.AppointmentReasonList)
{
foreach (ReasonCode Reason in ApptReason.ReasonCodeList)
{
AddInterfacePMReasonCode(PracticeID, Reason.Code, Reason.Description);
}
}
This is the easiest fix to the problems with your classes:
public class AppointmentReasonList : List<AppointmentReason>
{
}
public class ReasonCodeList : List<ReasonCode>
{
}
In case you were simply providing some code clips, and have a reason for not using the simplest fix, below is a fix that is closest to your original code:
public class AppointmentReasonList : ICollection<AppointmentReason>
{
public AppointmentReasonList()
{
AppointmentReasonLi = new List<AppointmentReason>();
}
public List<AppointmentReason> AppointmentReasonLi { get; set; }
public int Count
{
get { return AppointmentReasonLi.Count; }
}
public bool IsReadOnly
{
get
{
return false;
}
}
public void Add(AppointmentReason item)
{
AppointmentReasonLi.Add(item);
}
public void Clear()
{
AppointmentReasonLi.Clear();
}
public bool Contains(AppointmentReason item)
{
return AppointmentReasonLi.Contains(item);
}
public void CopyTo(AppointmentReason[] array, int arrayIndex)
{
AppointmentReasonLi.CopyTo(array, arrayIndex);
}
public IEnumerator<AppointmentReason> GetEnumerator()
{
return AppointmentReasonLi.GetEnumerator();
}
public bool Remove(AppointmentReason item)
{
return AppointmentReasonLi.Remove(item);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
public class ReasonCodeList : ICollection<ReasonCode>
{
public ReasonCodeList()
{
ReasonCodeLi = new List<ReasonCode>();
}
public List<ReasonCode> ReasonCodeLi { get; set; }
public int Count
{
get { return ReasonCodeLi.Count; }
}
public bool IsReadOnly
{
get
{
return false;
}
}
public void Add(ReasonCode item)
{
ReasonCodeLi.Add(item);
}
public void Clear()
{
ReasonCodeLi.Clear();
}
public bool Contains(ReasonCode item)
{
return ReasonCodeLi.Contains(item);
}
public void CopyTo(ReasonCode[] array, int arrayIndex)
{
ReasonCodeLi.CopyTo(array, arrayIndex);
}
public IEnumerator<ReasonCode> GetEnumerator()
{
return ReasonCodeLi.GetEnumerator();
}
public bool Remove(ReasonCode item)
{
return ReasonCodeLi.Remove(item);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Good luck, hope this helps.
-Eric.