当尝试使用Newtonsoft的Json.NET nuget库反序列化某些Json时,如果我不提供JsonSerializerSettings-为什么?我的collection-properties为null ?
我有一些有效的json数据,并将其反序列化为我的自定义类/ POCO。现在,所有简单的属性(例如strings,int's等)都已正确设置。我的简单子类也已正确设置(例如,User属性或BuildingDetails属性等)。
我所有的收藏都是null。这些设置器永远不会被调用(我在其中设置了一个断点,但它们没有被设置,但是其他设置器却被调用/设置了)。
例如。属性。
List<Media> Images { get { ... } set { ... } }
Run Code Online (Sandbox Code Playgroud)
例如。
var foo = new Foo();
var json = JsonConvert.Serialize(foo);
var anotherFoo = JsonConvert.Deserialize<Foo>(json);
// the collection properties on anotherFoo are null
Run Code Online (Sandbox Code Playgroud)
现在-这是疯狂的事情:当我使用a时,JsonSerializerSettings它现在可以工作:
// NOTE: ModifiedDataContractResolver <-- skips any property that is a type
/ ModifiedData (which is a simple custom class I have).
var …Run Code Online (Sandbox Code Playgroud)