I am getting the JSON request from http://www.viki.com/api/v2/channels.json
Now, I have the following classes from JSON:
public class RootObject
{
public int id { get; set; }
public string title { get; set; }
public string description { get; set; }
public string uri { get; set; }
public List<Episode> episodes { get; set; }
public Thumbnails2 thumbnails { get; set; }
public string timestamp { get; set; }
public List<object> genres { get; set; }
public string origin_code { get; set; }
}
public class Thumbnails2
{
public string c_220_160 { get; set; }
public string c_102_102 { get; set; }
public string c_180_130 { get; set; }
public string c_110_80 { get; set; }
public string xl { get; set; }
public string large { get; set; }
public string medium { get; set; }
public string small { get; set; }
public string c_320_300 { get; set; }
public string c_640_600 { get; set; }
public string c_95_70 { get; set; }
public string c_190_140 { get; set; }
public string c_280_200 { get; set; }
public string c_560_400 { get; set; }
}
Now I want to get the Values from large and medium in Thumbnails2 and all the episodes in List.
I tried with:
using (var wc = new WebClient())
{
var json = wc.DownloadString(jsonRequestURL);
dynamic vikiDesrialized = JsonConvert.DeserializeObject(json);
foreach (var item in vikiDesrialized)
{
//Console.WriteLine(item.title);
foreach (var thumnails in item.thumbnails)
{
JsonConvert.DeserializeObject(thumbNails);
}
}
}
But getting an exception which implies something else:
‘The invocation of the constructor on type ‘Viki.MainWindow’ that matches the specified binding constraints threw an exception.’
Line number ‘3’ and line position ‘9’.
Can I have those values using LINQ?
You don’t need the second deserialization
JsonConvert.DeserializeObject(thumbNails);either use
or