How to deserialize json string to object list in c# dot

前端 未结 4 1604
你的背包
你的背包 2020-12-15 21:56

I am working with the following JSON string

{
\"transactions\": 
[
   {
    \"paymentcharge\":\"0.0\",
    \"amount\":352,
    \"id\":13418,
    \"shippingc         


        
4条回答
  •  眼角桃花
    2020-12-15 22:30

    class WeapsCollection
    {
        public Dictionary Weapons { get; set; }
    
    }
    
    class WeaponList
    {
        public WeaponDetails AEK { get; set; }
        public WeaponDetails XM8 { get; set; }
    }
    
    class WeaponDetails
    {
        public string Name { get; set; }
        public int Kills { get; set; }
        public int Shots_Fired { get; set; }
        public int Shots_Hit { get; set; }
    }
    
    class Program  
    {
        static void Main(string[] args)
        {
            string json = @"
            {
               'weapons':
    
                        {
                           'aek':
                                {
                                   'name':'AEK-971 Vintovka',
                                   'kills':47,
                                   'shots_fired':5406,
                                   'shots_hit':858
                                },
                           'xm8':
                                {
                                   'name':'XM8 Prototype',
                                   'kills':133,
                                   'shots_fired':10170,
                                   'shots_hit':1790
                                },
                        }
    
            }";
    
            WeapsCollection weps = JsonConvert.DeserializeObject(json);
            Console.WriteLine(weps.Weapons.First().Value.Shots_Fired);            
    
            Console.ReadLine();
    
        }
    }
    

    Reply back in case of any issues.

提交回复
热议问题