I'm new to Json and trying to understand how I can parse it using Json.Net. I've tried to create objects for my json input, but I'm stuck. I'm not quite sure how to parse the input so I can iterate through it and output the season numbers and episode name.
Anyone who can point me in the right direction?
Json:
{
"data":{
"1921":{
"1":{
"airdate":"1921-03-20",
"name":"Cleaning Up!!?",
"quality":"N/A",
"status":"Wanted"
},
"2":{
"airdate":"1921-03-20",
"name":"Kansas City Girls Are Rolling Their Own Now",
"quality":"N/A",
"status":"Wanted"
},
"3":{
"airdate":"1921-03-20",
"name":"Did You Ever Take a Ride Over Kansas City Street 'in a Fliver'",
"quality":"N/A",
"status":"Wanted"
},
"4":{
"airdate":"1921-03-20",
"name":"Kansas City's Spring Clean-Up",
"quality":"N/A",
"status":"Wanted"
}
},
"1923":{
"1":{
"airdate":"2013-05-16",
"name":"Alice's Wonderland - aka - Alice in Slumberland",
"quality":"Unknown",
"status":"Downloaded"
}
}
},
"message":"",
"result":"success"
}
Code:
static void Main(string[] args)
{
RootObject data = JsonConvert.DeserializeObject<RootObject>(System.IO.File.ReadAllText(@"C:\Users\Benjamin\Desktop\json\input.txt"));
foreach (var e in data)
{
// Being able to output Season and Episode name like:
// 1921 - Cleaning Up!!?
}
}
public class RootObject
{
public Dictionary<int, Season> data { get; set; }
public string message { get; set; }
public string result { get; set; }
}
public class Season
{
public Dictionary<string, Episode> number { get; set; }
}
public class Episode
{
public string airdate { get; set; }
public string name { get; set; }
public string quality { get; set; }
public string status { get; set; }
}
datalook like after deserializing? Is it populated? In yourRootObjectyou have aDictionarycalleddataso you'd need to iterate overdata.datato start with.