0

I'm using json.net to deserialise some highly structured data - objects with lists of other objects in them. For the most part, this works fine.

But I have come across a situation where the json data we are getting is missing the list "node" complete. As in, its not showing an empty list "node" - it is missing the list "node" completely.

This is causing an error, saying the first int value of the object in the list cant be null.

How can I handle this better? If the list node is missing, I want it to just not create any lines in the deserialised object.

Thanks.

Shaggs
  • 111
  • 3
  • 11
  • *For such datamember, add* [JsonProperty(NullValueHandling=NullValueHandling.Ignore)] *for deserialization and* [DataMember(Name="property_name", EmitDefaultValue=false)] *for serialization*. – Graffito Feb 08 '17 at 23:06
  • Are you looking for [How to handle both a single item and an array for the same property using JSON.net](https://stackoverflow.com/questions/18994685/how-to-handle-both-a-single-item-and-an-array-for-the-same-property-using-json-n?noredirect=1)? If not, can you provide a concrete [mcve]? – dbc Feb 09 '17 at 00:13
  • Thanks Graffito. That looks like exactly the thing I was looking for. Turns out my problem was that one of the values was being passed back as null (it should never be null). So ended up solving this by just making it a nullable int. – Shaggs Feb 10 '17 at 09:35

0 Answers0