c# - domaintools json deserialize? -
i'm using asp.net mvc4 , json.net
and have json structure http://api.domaintools.com/v1/domaintools.com/whois/
how can deserialize own class ? looks bit complicated structure me realize how build class ?
i've tried far:
var json = "{\"response\":{\"registrant\":\"domaintools, llc\",\"registration\":{\"created\":\"1998-08-02\",\"expires\":\"2014-08-01\",\"updated\":\"2010-08-31\",\"registrar\":\"cheap-registrar.com\",\"statuses\":[\"ok\"]},\"name_servers\":[\"ns1.p09.dynect.net\",\"ns2.p09.dynect.net\",\"ns3.p09.dynect.net\",\"ns4.p09.dynect.net\"],\"whois\":{\"date\":\"2013-05-12\",\"record\":\"domain name: domaintools.com\\n\\nregistrant contact:\\n domaintools, llc\\n domain administrator (memberservices@domaintools.com)\\n +1.2068389035\\n fax: +1.2068389056\\n 2211 5th avenue\\n suite 201\\n seattle, wa 98121\\n us\\n\\nadministrative contact:\\n domaintools, llc\\n domain administrator (memberservices@domaintools.com)\\n +1.2068389035\\n fax: +1.2068389056\\n 2211 5th avenue\\n suite 201\\n seattle, wa 98121\\n us\\n\\ntechnical contact:\\n domaintools, llc\\n domain administrator (memberservices@domaintools.com)\\n +1.2068389035\\n fax: +1.2068389056\\n 2211 5th avenue\\n suite 201\\n seattle, wa 98121\\n us\\n\\n status: active\\n creation date: 13-jul-2002\\n expiration date: 13-jul-2016\\n name server: ns1.p09.dynect.net\\n name server: ns2.p09.dynect.net\\n name server: ns3.p09.dynect.net\\n name server: ns4.p09.dynect.net\\n\"}}}"; public class response { public string registrant { get; set; } public registration registration { get; set; } public list<string> name_servers { get; set; } public whois whois { get; set; } } public class registration { public datetime created { get; set; } public datetime expires { get; set; } public datetime updated { get; set; } public string registrar { get; set; } public list<string> statuses { get; set; } } public class whois { public datetime date { get; set; } public string record { get; set; } } var response = jsonconvert.deserializeobject<response>(json); >> null
it start http://json2csharp.com/ site find right structure, example gives:
public class registration { public string created { get; set; } public string expires { get; set; } public string updated { get; set; } public string registrar { get; set; } public list<string> statuses { get; set; } } public class whois { public string date { get; set; } public string record { get; set; } } public class response { public string registrant { get; set; } public registration registration { get; set; } public list<string> name_servers { get; set; } public whois whois { get; set; } } public class rootobject { public response response { get; set; } }
you need use rootobject
class want deserialize:
var response = jsonconvert.deserializeobject<rootobject>(json);
Comments
Post a Comment