How to handle null/empty values in JsonConvert.DeserializeObject

后端 未结 4 712
执笔经年
执笔经年 2020-12-12 22:52

I have the following code:

return (DataTable)JsonConvert.DeserializeObject(_data, (typeof(DataTable)));

Then, I tried:

var          


        
4条回答
  •  半阙折子戏
    2020-12-12 23:04

    The accepted answer works perfectly. But in order to make the answer apply globally, in startup.cs do the following:

        services.AddControllers().AddNewtonsoftJson(options =>
        {
            options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
        });
    

    The answer has been tested in a .Net Core 3.1 project.

提交回复
热议问题