Json Restsharp不是反序列化响应

Json Restsharp不是反序列化响应,json,deserialization,restsharp,Json,Deserialization,Restsharp,我在使用RestSharp反序列化响应时遇到问题。我得到以下JSON响应 { "client": { "clientnr":"1", "contact":" Johnny Bravo", "showcontact":"false", "company":"Acme International", "address":"Washington Street 250", "zipcode":"1234567", "city":"SOMECIT

我在使用RestSharp反序列化响应时遇到问题。我得到以下JSON响应

{
  "client": {
    "clientnr":"1",
    "contact":" Johnny Bravo",
    "showcontact":"false",
    "company":"Acme International",
    "address":"Washington Street 250",
    "zipcode":"1234567",
    "city":"SOMECITYNAME",
    "country":"146",
    "phone":"0048122123123",
    "mobile":"myMobileNumber",
    "email":"some@email.com",
    "bankcode":"",
    "biccode":"",
    "taxnumber":"NL001234567B01",
    "tax_shifted":"true",
    "lastinvoice":"",
    "sendmethod":"email",
    "paymentmethod":"bank",
    "top":"0",
    "stddiscount":"0",
    "mailintro":"",
    "reference": {
      "line1":"",
      "line2":null,
      "line3":null
     },
    "notes":"",
    "notes_on_invoice":"false",
    "active":"true",
    "default_doclang":"en",
    "default_email":"0",
    "currency":"EUR",
    "mandate_id":"",
    "mandate_date":"",
    "collecttype":"FRST",
    "tax_type":"extax",
    "default_category":"0"
  }
}   
我已经使用JSON来csharp以创建类

public class Reference
{
    public string line1 { get; set; }
    public object line2 { get; set; }
    public object line3 { get; set; }
}

public class Client
{
    public string clientnr { get; set; }
    public string contact { get; set; }
    public string showcontact { get; set; }
    public string company { get; set; }
    public string address { get; set; }
    public string zipcode { get; set; }
    public string city { get; set; }
    public string country { get; set; }
    public string phone { get; set; }
    public string mobile { get; set; }
    public string email { get; set; }
    public string bankcode { get; set; }
    public string biccode { get; set; }
    public string taxnumber { get; set; }
    public string tax_shifted { get; set; }
    public string lastinvoice { get; set; }
    public string sendmethod { get; set; }
    public string paymentmethod { get; set; }
    public string top { get; set; }
    public string stddiscount { get; set; }
    public string mailintro { get; set; }
    public Reference reference { get; set; }
    public string notes { get; set; }
    public string notes_on_invoice { get; set; }
    public string active { get; set; }
    public string default_doclang { get; set; }
    public string default_email { get; set; }
    public string currency { get; set; }
    public string mandate_id { get; set; }
    public string mandate_date { get; set; }
    public string collecttype { get; set; }
    public string tax_type { get; set; }
    public string default_category { get; set; }

} 
然而,每次调用API时,我都会得到null(因此反序列化似乎不起作用)。 我一直在调试它,所以我会捕捉到一些错误,但是过程进行得很顺利,没有任何错误

我的电话号码如下

var client = new RestClient("https://www.myapi.com/");
var request = new RestRequest("api/xyz/something", Method.GET);
var response2 = client.Execute<Client>(request);
var client=new RestClient(“https://www.myapi.com/");
var request=new RestRequest(“api/xyz/something”,Method.GET);
var response2=client.Execute(请求);

有什么地方我犯了错误吗

这是因为您的
客户机:{}
被包装在JSON对象中。最简单的方法是为C#
客户机
类添加一些包装器

public class Container
{
    public Client Client { get; set; }
}

...

var response = client.Execute<Container>(request);
公共类容器
{
公共客户端{get;set;}
}
...
var response=client.Execute(请求);

嘿!我发现这个问题的答案是添加request.RootElement=“client”;最简单的方法是:D