You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

System.Text.Json.JsonSerializer支持序列化的属性与字段有哪些?

System.Text.Json.JsonSerializer 默认可序列化成员范围

以下为默认配置(未自定义JsonSerializerOptions、未添加[JsonInclude]等序列化特性)下的支持情况:

Private/Protected/Internal FieldsPrivate/Protected/Internal PropertiesPublic FieldsPublic Properties
Readonly❌❌❌✅
Writeonly❌❌❌❌
Read & Write❌❌❌✅

额外规则说明

  • 若需要序列化公共字段,需手动配置JsonSerializerOptions.IncludeFields = true,开启后公共只读、公共读写字段都会被纳入序列化范围。
  • 若需要序列化非public的成员,需给对应成员显式添加[JsonInclude]特性,同时要求属性的get/set访问器和对应成员的访问权限匹配。
  • 只写属性默认无论如何都不会参与序列化(输出JSON),仅当显式添加[JsonInclude]特性时,才会在反序列化阶段接收JSON中的对应值完成赋值。

内容的提问来源于stack exchange,提问作者trinalbadger587

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 05:54:02