-2

I have following json:

{  
   "578080":{  
      "success":true,
      "data":{  
         "price_overview":{  
            "currency":"USD",
            "initial":1799,
            "final":1799,
            "discount_percent":0
         }
      }
   }
}

I want to search "initial".

How can I do this using Json.Net or any other efficient means in C#?

Note : i haven't tried anything because i am unsure where to start

TheGeneral
  • 79,002
  • 9
  • 103
  • 141

1 Answers1

0

Since this is a Dictionary<string,object> you can follow this, Deserialize a Dictionary

public class PriceOverview
{
    public string currency { get; set; }
    public int initial { get; set; }
    public int final { get; set; }
    public int discount_percent { get; set; }
}

public class Data
{
    public PriceOverview price_overview { get; set; }
}

public class RootObject
{
    public bool success { get; set; }
    public Data data { get; set; }
}

var results = JsonConvert.DeserializeObject<Dictionary<string, RootObject>>(json);

foreach (var result in results)
{
   Console.WriteLine(result.Key);
   Console.WriteLine(result.Value.data.price_overview.currency);
   Console.WriteLine(result.Value.data.price_overview.initial);
   Console.WriteLine(result.Value.data.price_overview.final);
   Console.WriteLine(result.Value.data.price_overview.discount_percent);

}

Output

578080
USD
1799
1799
0

Full demo here

TheGeneral
  • 79,002
  • 9
  • 103
  • 141