System.Text.Json 序列化对所有 JSON 属性名称使用 camel 大小写

asp.net core3.x 新增的序列号接口System.Text.Json

序列化时,如果要对所有 JSON 属性名称使用 camel 大小写

将 JsonSerializerOptions.PropertyNamingPolicy 设置为 JsonNamingPolicy.CamelCase即可

 例:

1 var serializeOptions = new JsonSerializerOptions
2 {
3     PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
4     WriteIndented = true
5 };
6 jsonString = JsonSerializer.Serialize(weatherForecast, serializeOptions);
View Code

猜你喜欢

转载自www.cnblogs.com/jie566/p/12571614.html