Is there way to deserialize invalid json?
For example, next JSON deserialization will fail with JsonReaderException
{
'sessionId': 's0j1',
'commandId': 19,
'options': invalidValue // invalid value
}
because options property value is invalid.
Is there a nice way to get sessionId and commandId values even if options value is invalid?
I know it's possible to handle errors during deserialization (http://www.newtonsoft.com/json/help/html/SerializationErrorHandling.htm)
var json = "{'sessionId': 's0j1', 'commandId': 19, 'options': invalidValue}";
var settings = new JsonSerializerSettings
{
Error = delegate(object sender, ErrorEventArgs args)
{
args.ErrorContext.Handled = true;
}
});
var result = JsonConvert.DeserializeObject(json, settings);
Bit it will result in result = null.