c# - Deserialize json string to a class using NewtonSoft.JSON -
this json string
{\"currentdatetime\":\"21-09-2014 17:48:00\",\"currenttime\":\"17:48:00.2360971\"}
i want convert class
public class currentdatetimejson { public string currentdatetime { get; set; } public string currenttime { get; set; } }
i using newtonsoft.json deserialize.
following code deserialize
var = jsonconvert.deserializeobject<currentdatetimejson>(jsonstring);
i getting following error
error converting value "{"currentdatetime":"21-09-2014 17:51:56","currenttime":"17:51:56.9643252"}" type 'currentdatetimejson'.
edit
code produces json
public string getcurrentdatetimejson() { currentdatetime cdt = new currentdatetime() { currentdatetime = datetime.now.tostring(), currenttime = datetime.now.timeofday.tostring() }; string json = jsonconvert.serializeobject(cdt); return json; }
inner exception
"could not cast or convert system.string currentdatetimejson."
Comments
Post a Comment