In my C# project, I have occasion to deserialize JSON that may not be correct. Hence, errors are possible. At the moment, I am wrapping it in a try block, and catching exceptions by returning null. This works, but it would be nicer to tell the library not to throw an exception in the first place. Is that possible?
My current code:
public static NodeModel FromJsonString(string json)
{
NodeModel r = null;
JsonConverter converter = JsonConverters.ReferenceHierarchyCreation;
try
{
r = JsonConvert.DeserializeObject<NodeModel>(json, converter);
}
catch
{
}
return r;
}