c# - Array JSON deserialize -


i'm trying data website rss converting json. got json string:

http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http%3a%2f%2frss.tecmundo.com.br%2ffeed

i'm using lists values got error "cannot create instance of abstract class or interface" , don't know how solve it. happens in line.

ilist<news> content = new ilist<news>(); 

here code.

public class news {     public string author { get; set; }     public string title { get; set; }     public string content { get; set; }     public string contentsnippet { get; set; }     public string link { get; set; }     public string publisheddate { get; set; }      public string[] getfeed(string website)     {         string path = @"http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=" + website;         var json = new webclient().downloadstring(path);         jobject jsonobject = jobject.parse((string)json);          ilist<jtoken> jsondata = jsonobject["responsedata"]["feed"]["entries"]["0"].children().tolist();         ilist<news> content = new ilist<news>();          foreach(jtoken data in jsondata)         {             news finaldata1 = jsonconvert.deserializeobject<news>(jsondata.tostring());             content.add(finaldata1);         }          return new string[] { "i must return here." };     } } 

here tool i'm using visualize better json string: http://jsonschema.net/#/

the error you're getting has nothing json. because you're trying create instance of interface. could fix giving concrete list<t> class:

ilist<news> content = new list<news>(); 

however, simpler way of converting ilist<jtoken> ilist<news> use linq again - can of in 1 step pretty easily:

 ilist<news> content = jsonobject["responsedata"]["feed"]["entries"]["0"]     .children()     .select(token => jsonconvert.deserializeobject<news>(token.tostring())     .tolist(); 

that compiles, isn't want due data you've got. entries array, want:

jarray array = (jarray) jsonobject["responsedata"]["feed"]["entries"]; var content = array     .select(token => jsonconvert.deserializeobject<news>(token.tostring())     .tolist(); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -