使用JSON.NET进行序列化时隐藏C#属性
发布时间:2020-12-16 19:52:24 所属栏目:百科 来源:网络整理
导读:我们如何隐藏使用 JSON.NET库进行序列化的C#属性.假设我们有班级客户 public class Customer{ public int CustId {get; set;} public string FirstName {get; set;} public string LastName {get; set;} public bool isLocked {get; set;} public Customer()
|
我们如何隐藏使用
JSON.NET库进行序列化的C#属性.假设我们有班级客户
public class Customer
{
public int CustId {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
public bool isLocked {get; set;}
public Customer() {}
}
public class Test
{
Customer cust = new Customer();
cust.CustId = 101;
cust.FirstName = "John"
cust.LastName = "Murphy"
string Json = JsonConvert.SerializeObject(cust);
}
JSON
此对象转换为json,但我没有指定isLocked属性.由于库将序列化整个类,有没有办法在json序列化过程中忽略属性或者我们可以在属性上添加任何属性. 编辑: JSON
谢谢
使用JSON.Net属性:
public class Customer
{
public int CustId {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
[JsonIgnore]
public bool isLocked {get; set;}
public Customer() {}
}
有关更多信息:http://james.newtonking.com/json/help/index.html?topic=html/SerializationAttributes.htm (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 为什么从Ruby调用Bash命令会抛出错误?
- macos – CKQueryOperation queryCompletionBlock只运行3次
- 使用C#将FoxPro表导入SQL – 一个表工作,一个表不工作
- Cocos Creator 热更新
- PG的数据类型(一)——数组类型
- ios – dyld`__abort_with_payload:没有错误消息
- 使用ajaxfileupload上传文件
- systemd deletes shared memory segment in postgresql
- ruby-on-rails-4 – 在Rails中使用Postgres多模式数据库
- c – 视频录制在IMFSinkWriter-> Finalize()上挂起;
