Deserializing json into a list of objects - Cannot create and populate list type [duplicate]

可紊 提交于 2019-12-09 03:09:28

The problem is that json.net doesn't know how to add data to your Battles class. There is couple way to fix that:

  1. Deserialize your data to a list:

    JsonConvert.DeserializeObject<List<RootObject>>(jsr.ReadToEnd());

  2. Instead of implementing IEnumerable, implement ICollection<RootObject> in your Battles class, then JsonConvert will properly populate it with data:

    public class Battles: ICollection<RootObject>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!