c# - ServiceStack Deserialization not building an object -
c# - ServiceStack Deserialization not building an object -
i'm using servicestack deserialize json got web service object. process works (no exceptions) have no access classes within deserialized object.
my code calls this:
loginresultmodel result = new loginresultmodel { avatars = new avatars(), country = new country(), rootobject = new rootobject() }; result = client.post<loginresultmodel>(url, postdata); once result (of type loginresultmodel), cant access within of it! intellisense wont help - "result." dont show related class.
i'm guessing i'm doing wrong hierarchy? (weird since no exceptions thrown). doing wrong?
json in deserialized form (used json2csharp):
public class loginresultmodel { /// <summary> /// islogedin method /// </summary> public country country { get; set; } public avatars avatars { get; set; } public rootobject rootobject { get; set; } } public class country { public string name { get; set; } public string a2 { get; set; } public int code { get; set; } public int phoneprefix { get; set; } } public class avatars { public string little { get; set; } public string medium { get; set; } public string big { get; set; } } public class rootobject { public int cid { get; set; } public string username { get; set; } public country country { get; set; } public string url { get; set; } public int affiliateid { get; set; } public avatars avatars { get; set; } public bool isloggedin { get; set; } public bool allowcommunity { get; set; } public string token { get; set; } public int tokenexpirationinminutes { get; set; } public bool iskycrequired { get; set; } }
your loginresultmodel class not contain public properties. there nil serialise, , have empty result.
what have done created other classes within loginresultmodel believe meant implement properties.
what should create classes this:
class="lang-cs prettyprint-override">public class country { public string name { get; set; } public string a2 { get; set; } public int code { get; set; } public int phoneprefix { get; set; } } public class avatars { public string little { get; set; } public string medium { get; set; } public string big { get; set; } } public class rootobject { public int cid { get; set; } public string username { get; set; } public country country { get; set; } public string url { get; set; } public int affiliateid { get; set; } public avatars avatars { get; set; } public bool isloggedin { get; set; } public bool allowcommunity { get; set; } public string token { get; set; } public int tokenexpirationinminutes { get; set; } public bool iskycrequired { get; set; } } where loginresultmodel has properties of type of other classes:
public class loginresultmodel { public country country { get; set; } public avatars avatars { get; set; } public rootobject rootobject { get; set; } } then in action method need populate loginresultmodel instance of objects:
public class myloginservice : service { public loginresultmodel post(loginrequest request) { // login logic here homecoming new loginresultmodel { country = new country { name = "united states", a2 = "something", code = 1, phoneprefix = 555}, avatars = new avatars { little = "small.png", medium = "medium.png", big = "large.png" }, rootobject = new rootobject { cid = 123, username = "", ... } }; } } hope helps.
c# servicestack json-deserialization
Comments
Post a Comment