Json.Net deserialize JSON objects with index as name [duplicate]

爷,独闯天下 提交于 2019-12-06 00:35:47

You don't need FeaturedArticles class, you can deserialize the JSON into a Dictionary<string, Articles> like this:

private void fetchFeaturedArticles()
{
    var client = new RestClient (_featuredArticlesJsonUrl);
    var request = new RestRequest (Method.GET);
    var response = client.Execute (request);

    Dictionary<string, Articles> _featuredArticles = JsonConvert.DeserializeObject<Dictionary<string, Articles>>(response.Content);

    foreach (string key in _featuredArticles.Keys)
    {
        Console.WriteLine(_featuredArticles[key].Title);
    }

}

Demo: https://dotnetfiddle.net/ZE1BMl

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