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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM