.NETCore3.0中System.Text.Json的使用

在DotNetCore3.0中json的使用不再需要额外的引入Newtonsoft.Json的包,因为在3.0中提供了一个新型的json操作工具类-System.Text.Json。

首先我们先新建一个测试的对象
.NETCore3.0中System.Text.Json的使用
然后稍微对System.Text.Json中的序列化和反序列化的方法进行封装
.NETCore3.0中System.Text.Json的使用
接着新建一个测试的控制器进行调试显示结果
.NETCore3.0中System.Text.Json的使用
.NETCore3.0中System.Text.Json的使用
就这样结果很明显的出来了。

其实我们还还可以自己自定义一些属性来控制序列化行为,就好像,忽略属性或者是指定属性的名称等
.NETCore3.0中System.Text.Json的使用
自定义属性前的请求结果:
.NETCore3.0中System.Text.Json的使用
自定义属性后的请求结果:
.NETCore3.0中System.Text.Json的使用