惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
WordPress大学
WordPress大学
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
博客园 - Franky
D
Docker
小众软件
小众软件
阮一峰的网络日志
阮一峰的网络日志
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
U
Unit 42
M
MIT News - Artificial intelligence
B
Blog
GbyAI
GbyAI
C
Check Point Blog
P
Proofpoint News Feed
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
IT之家
IT之家
Google DeepMind News
Google DeepMind News
V
V2EX
Stack Overflow Blog
Stack Overflow Blog

博客园 - simadi

PostgreSQL安装设置 Avalonia程序部署在统信系统,内存一直增大 vue项目 重装依赖包 cursor 更改项目typescript版本 nodejs项目,新建表步骤 Zig 语言 使用NVM安装node 我的iis10里有很多网站,现在要迁移到另一个服务器,怎么做最简单方便 Browser Harness MQTT测试工具 从华为手机导出照片到Win11 emoji大全 Sqlite“无法加载 DLL“e_sqlite3”: 找不到指定的模块”解决方法 c# 请求https网站失败 Edge安装EPUB阅读器 curl,wget,HTTPie PowerShell Winget Windows 包管理器 Windows11 升级到25H2 ai+.net postgresql windows 精简版 Windows X-Lite Visual Studio 2026 新建Avalonia项目选这个,第一个会新建两个项目 隆重推出免费工具FdyRegulator1.0 Visual Studio 2026 新建axaml编码是gbk 中文运行乱码 ffmpeg 下载地址 elasticsearch + .net 开发使用的第三方库 Avalonia 开源项目,学习用 吉他自学笔记
System.Text.Json
simadi · 2026-01-21 · via 博客园 - simadi

https://mp.weixin.qq.com/s/3M6bhK_BvXhcBBd2yOZK8A

快速参考:行为对齐配置映射表

Newtonsoft.Json 行为System.Text.Json 默认行为System.Text.Json 配置 (JsonSerializerOptions)备注
「反序列化大小写不敏感」 区分大小写 PropertyNameCaseInsensitive = true ASP.NET Core默认已开启此选项。
「驼峰命名策略」 PascalCase (与C#属性名一致) PropertyNamingPolicy = JsonNamingPolicy.CamelCase ASP.NET Core默认已开启此选项。
「忽略JSON注释」 抛出异常 ReadCommentHandling = JsonCommentHandling.Skip  
「忽略尾随逗号」 抛出异常 AllowTrailingCommas = true  
「序列化时忽略null值」 包含null值 DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull  
「反序列化带引号的数字」 抛出异常 NumberHandling = JsonNumberHandling.AllowReadingFromString 例如,将"123"反序列化为int类型。
「处理循环引用」 抛出异常 ReferenceHandler = ReferenceHandler.IgnoreCycles IgnoreCycles将循环点置为null,是API场景的常用选择。
「枚举序列化为字符串」 序列化为数字 添加 new JsonStringEnumConverter() 到 Converters 集合 Newtonsoft.Json中也有类似的StringEnumConverter
「中文字符转义」 转义非ASCII字符 Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping 适用于API和AI交互,减少Token消耗。
「动态操作JSON (JObject)」 JsonDocument (只读) 使用 JsonNode / JsonObject / JsonArray .NET 6及以后版本可用,功能对标JObject