c# - Error with deserializing complex Json -
i deserialize complex json (spotify playlist) , root level values cannot branches values. google problem, try different options without success but, assume silly mistake or lack of knowledge therefore ask missing?
my classes are:
public class playlist { public string collaborative { get; set; } public string description { get; set; } //public <externalurls> external_urls { get; set; } //object //public list<followers> followers { get; set; } //object public string href { get; set; } public string id { get; set; } //public list<image> images { get; set; } //array public string name { get; set; } } public class tracks { public string href { get; set; } public item items { get; set; } //object public string limit { get; set; } public string next { get; set; } public string offset { get; set; } public string previous { get; set; } public string total { get; set; } }
and code deserialize looks that:
streamreader responsefromserver = new streamreader(mywebresponse.getresponsestream()); var dataresponse = responsefromserver.readtoend(); responsefromserver.close(); var elements = new javascriptserializer().deserialize<playlist>(dataresponse); rootbuffer.addrow(); rootbuffer.collaborative = elements.collaborative.tostring(); foreach (tracks trs in elements.tracks) { tracksbuffer.addrow(); tracksbuffer.href = trs.href.tostring() }
i genereated classes using excellent site: json2csharp.com
and used existing deserialization code following classes. populated data including child collections (brace yourself, it's long one):
public class playlist { public bool collaborative { get; set; } public string description { get; set; } public externalurls external_urls { get; set; } public followers followers { get; set; } public string href { get; set; } public string id { get; set; } public list<image> images { get; set; } public string name { get; set; } public owner owner { get; set; } public bool @public { get; set; } public string snapshot_id { get; set; } public tracks tracks { get; set; } public string type { get; set; } public string uri { get; set; } } public class externalurls { public string spotify { get; set; } } public class followers { public object href { get; set; } public int total { get; set; } } public class image { public object height { get; set; } public string url { get; set; } public object width { get; set; } } public class externalurls2 { public string spotify { get; set; } } public class owner { public externalurls2 external_urls { get; set; } public string href { get; set; } public string id { get; set; } public string type { get; set; } public string uri { get; set; } } public class externalurls3 { public string spotify { get; set; } } public class addedby { public externalurls3 external_urls { get; set; } public string href { get; set; } public string id { get; set; } public string type { get; set; } public string uri { get; set; } } public class externalurls4 { public string spotify { get; set; } } public class image2 { public int height { get; set; } public string url { get; set; } public int width { get; set; } } public class album { public string album_type { get; set; } public list<object> available_markets { get; set; } public externalurls4 external_urls { get; set; } public string href { get; set; } public string id { get; set; } public list<image2> images { get; set; } public string name { get; set; } public string type { get; set; } public string uri { get; set; } } public class externalurls5 { public string spotify { get; set; } } public class artist { public externalurls5 external_urls { get; set; } public string href { get; set; } public string id { get; set; } public string name { get; set; } public string type { get; set; } public string uri { get; set; } } public class externalids { public string isrc { get; set; } } public class externalurls6 { public string spotify { get; set; } } public class track { public album album { get; set; } public list<artist> artists { get; set; } public list<object> available_markets { get; set; } public int disc_number { get; set; } public int duration_ms { get; set; } public bool @explicit { get; set; } public externalids external_ids { get; set; } public externalurls6 external_urls { get; set; } public string href { get; set; } public string id { get; set; } public string name { get; set; } public int popularity { get; set; } public string preview_url { get; set; } public int track_number { get; set; } public string type { get; set; } public string uri { get; set; } } public class item { public string added_at { get; set; } public addedby added_by { get; set; } public bool is_local { get; set; } public track track { get; set; } } public class tracks { public string href { get; set; } public list<item> items { get; set; } public int limit { get; set; } public object next { get; set; } public int offset { get; set; } public object previous { get; set; } public int total { get; set; } }
hope helps.
Comments
Post a Comment