Deserialize JSON into Object C#

前端 未结 5 1660
广开言路
广开言路 2020-11-28 14:06

Hello I am in desperate need of some help. I have a json file, with an array of json objects. I cannot figure out how to deserialize it into a list of this object.

5条回答
  •  误落风尘
    2020-11-28 14:20

    Try using Newtonsoft.Json library.

    Add this https://www.nuget.org/packages/Newtonsoft.Json/7.0.1 on your project.

    This is the link for my solution: https://dotnetfiddle.net/eqJXTy

    And then:

    List> obj =
        Newtonsoft.Json.JsonConvert.
            DeserializeObject>>(jsonString);
    
    foreach(Dictionary lst in obj)
    {
        Console.WriteLine("--NewObject--");
        Console.WriteLine(string.Format("Rk: {0} Gcar: {1}", lst["Rk"], lst["Gcar"]));
        foreach(KeyValuePair item in lst)
        {
            Console.WriteLine(string.Format("Key: {0} Value: {1}", item.Key, item.Value));
        }
    }
    

    Happy to help you!

提交回复
热议问题