Ignore parsing errors during JSON.NET data parsing

前端 未结 3 1511
无人共我
无人共我 2020-11-30 02:42

I have an object with predefined data structure:

public class A
{
    public string Id {get;set;}
    public bool? Enabled {get;set;}
    public int? Age {ge         


        
3条回答
  •  隐瞒了意图╮
    2020-11-30 03:19

    Same thing as Ilija's solution, but a oneliner for the lazy/on a rush (credit goes to him)

    var settings = new JsonSerializerSettings { Error = (se, ev) => { ev.ErrorContext.Handled = true; } };
    JsonConvert.DeserializeObject(yourJsonStringVariable, settings);
    

    Props to Jam for making it even shorter =)

提交回复
热议问题