我有一个类:
public class CustomResponse
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Message {get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Details {get; set; }
}
然后,我尝试将JSON字符串反序列化为这个类:
var settings = new JsonSerializerSettings
{
NullValueHandling.Ignore,
MissingMemberHandling.Ignore,
};
var customResponse = JsonConvert.Deserialize<CustomResponse>(jsonString, settings);
例如我的JSON字符串:
{"DocumentId":"123321", "DocumentNumber":"ABC123"}
因此,我有一个对象,其中所有属性都为NULL,但
customResponse
不为NULL。如何在结果中获得NULL?
JsonConverter
来实现这个功能。 - dbccustomResponse
是null
呢? - Daniel A. WhiteCustomResponse
可以有一个计算/只读属性,比如IsEmpty
或IsValid
,用于检测其是否有效。 - Daniel A. White