Currently, I have some JSON data that I am attempting to deserialize using the DataContractJsonSerializer
class. However, one of the arrays in the data contains multiple types of objects. Is there a way to deserialize this data properly? I am aware that a very similar question exists, but I would prefer not to use Json.NET or any other third-party libraries.
EDIT: A small example:
In this instance, let's say the JSON is of form [{"foo":string},{"bar":string},{"foo":string},{"foo":string},...]
where each element is either of form {"foo":string}
or {"bar":string}
. Then, the contracts could be set up as such:
[DataContract]
class Foo { [DataMember] public string foo; }
[DataContract]
class Bar { [DataMember] public string bar; }
In this context, my question is, how do I deserialize this array of Foo
s and Bar
s?