c# - 属性未通过 newtonsoft 在 Json 中序列化
问题描述
类中定义了许多属性,但其中一个属性没有被序列化(使用 newtonsoft),下面提到了该属性:
public override string Value
{
set
{
if (value == null)
{
this.Null = true;
}
else if (value == string.Empty)
{
_A = string.Empty;
_P = string.Empty;
_S = string.Empty;
}
else
{
value = _A + _P + _S;
}
}
}
但是当我们在属性中定义 getter 时,它会被序列化,所以请建议;我们不想将 getter 放在属性中。
解决方案
将[JsonProperty]
属性设置为您的属性。但总的来说,你可以让你的吸气剂private
- 所以你不会将数据暴露给其他类,但它可以帮助解决你的问题。
推荐阅读
- python - 创建正则表达式 for 循环,根据文档搜索列表中的每个字符串
- python - 用于反复试验的 Python 多重 for 循环
- kentico - 由于 Kentico 9 中的许可证限制,无法将自定义表添加到所选站点
- node.js - Postgresql-Nodejs 连接错误(ECONNREFUSED)Windows 10
- javascript - JavaScript中有用户输入吗?
- python - 多处理功能后python代码变慢
- javascript - Laravel 视图计数器 (PUT 405 (Method Not Allowed) ) 问题
- javascript - 为什么 document.getElementById 不起作用?
- php - 从发布的变量 php 创建一个数组
- java - 无法使用刷新的令牌改造请求