Fork on Github
Download the Nuget package
The previous tutorial focused on deserialising simple JSON objects. This tutorial describes the process of deserialising a more complex object using JSON#.
Let’s use the ComplexObject class that we’ve leveraged in earlier tutorials:
Let’s instantiate this with some values, and serialise to JSON. I won’t bloat this post with details on how to serialise, covered in previous posts. Here is our serialised ComplexObject instance:
Notice that we have 2 collections. A simple collection of Doubles
, and a more complex collection of ComplexArrayObjects
. Let’s start with those.
First, create a new class, ComplexObjectDeserialiser
, and implement the required constructor
and Deserialise
method.
Remember this method from the previous tutorial?
This effectively parses the JSON and loads each element into a NameValueCollection
. This is fine for simple properties, however collection-based properties would cause the deserialiser to load each collection-element as…