How to ignore an error using Json.NET without damaging what has already been read

1

Is there any way to continue "deserializing" an object using Json.NET , even when a property is corrupted and without damaging the which has already been "read"?

    
asked by anonymous 26.01.2016 / 02:58

1 answer

1

Yes, it is possible through the use of a JsonConverter . The JsonConverter class converts an object to JSON and vice versa, but this process can be customized if you create a class that derives from it and override methods JsonConverter.ReadJson and / or JsonConverter.WriteJson .

The official Json.NET documentation has a very simple example of how a custom JsonConverter can be implemented. Here the example link.

Note that you can also specify a JsonConverter to be used as the default during the process of "serializing" and "deserializing" an object through the JsonConverterAttribute , this can be useful for accelerating development.

I also recommend that you take a look at the example of answer this question in Stack Overflow Using Json.NET converters to deserialize properties . It can be very useful as a starting point for developing your custom JsonConverter .

    
26.01.2016 / 03:56