c# - Json RestSharp deserilizing Response Data null -


i use restsharp access rest api. data poco. restsharp client looks this:

var client = new restclient(@"http:\\localhost:8080");         var request = new restrequest("todos/{id}", method.get);         request.addurlsegment("id", "4");         //request.onbeforedeserialization = resp => { resp.contenttype = "application/json"; };         //with enabling next line new empty object of todo         //as data         //client.addhandler("*", new jsondeserializer());         irestresponse<todo> response2 = client.execute<todo>(request);         todo td=new jsondeserializer().deserialize<todo>(response2);          var name = response2.data.name; 

my class jsonobject looks this:

public class todo {     public int id;     public string created_at;     public string updated_at;     public string name; } 

and json response:

{     "id":4,     "created_at":"2015-06-18 09:43:15",     "updated_at":"2015-06-18 09:43:15",     "name":"another random test" } 

per documentation, restsharp deserializes properties , you're using fields.

restsharp uses class starting point, looping through each publicly-accessible, writable property , searching corresponding element in data returned.

you need change todo class following:

public class todo {     public int id { get; set; }     public string created_at { get; set; }     public string updated_at { get; set; }     public string name { get; set; } } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -