我正在尝试反序列化以下JSON:
{
"ListA":[],
"ListB":
[
{
"Item1":{"Id":"-1"}
}
]
}
ListB正确反序列化,但ListA只是反序列化为null;我希望它反序列化为一个空列表。
我反序列化此JSON的代码如下:
var settings = new JsonSerializerSettings();
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
settings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
settings.TypeNameHandling = TypeNameHandling.Auto;
settings.Binder = new TypeNameSerializationBinder(modelBindingTypeAssembliesFactory);
var myObject = JsonConvert.DeserializeObject<MyType>(Encoding.ASCII.GetString(jsonContent), settings);
有什么想法吗?我原以为正确的行为是[]变成一个空列表。