JsonPropertyAttribute是命名空间Newtonsoft.Json下的特性,我使用的是System.Runtime.Serialization.Json来序列化,因此序列化的时候忽略了JsonPropertyAttribute(PropertyName)
解决办法:System.Runtime.Serialization的DataContractAttribute和DataMemberAttribute都有一个Name属性,直接修改即可。
eg.
[DataMember(Name = "exec_type")]
public int ExecType { get; set; }
当使用System.Runtime.Serialization.Json进行序列化时,遇到一个问题:序列化过程忽略了JsonPropertyAttribute(PropertyName)。解决方法是改用DataContractAttribute和DataMemberAttribute,通过设置其Name属性来指定序列化的字段名。例如:[DataMember(Name=exec_type)] public int ExecType { get; set; }
3352

被折叠的 条评论
为什么被折叠?



