从StackOverflow里找到的答案.发现对最新的Newtownsoft的JSON序列化也同样适用. https://stackoverflow.com/questions/5818513/xml-serialization-hide-null-values public bool ShouldSerializeMyNullableInt() { return MyNullableInt.HasValue; } 举例子: public class Person { public string…