c# - Deserialize JSON object that has the same object as member in it -
i having trouble de-serializing json has structure following.
public class entity { public int id; public string entityname; private list<entity> _items; //sub entities public ireadonlylist<entity> items { get{ return _items; } } } while in debug mode, able see items > 0 via json visualizer(as in below image) when try de-serialize items count = 0
i tried using following statements, still no luck.
var json = await response.getcontentasync<string>(); try 1
var deserializedlist = jsonconvert.deserializeobject<ienumerabld<entity>>json); try 2
var settings = new jsonserializersettings{maxdepth = 5}; var deserializedlist = jsonconvert.deserializeobject<ireadonlylist<entity>>(json, settings); any regarding appreciated.
the first option make ilist<entity> if want keep ireadonlylist<entity> can supplying setter -
public ireadonlylist<entity> items { { return _items; } set { _items = _items ?? new list<entity>(); if (value == null) return; _items.addrange(value); } } here example -


Comments
Post a Comment