RestSharp Json在Content中但不在Data中

时间:2017-06-26 11:33:44

标签: c# restsharp json-deserialization

我有一个班级Meeting

public int idMeeting { get; set; }
public DateTime dateTime { get; set; } // DateTime(Int32, Int32, Int32, Int32, Int32, Int32)  Jahr, Monat, Tag, Stunde, Minute und Sekunde.
public int idRoom { get; set; }
public int idPerson { get; set; }
public List<Person> participants { get; set; }

Person

public int idPerson { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string phonenumber { get; set; }
public string mailadress { get; set; }
public int idCompany { get; set; }

使用RestSharp请求我从Web服务获取此信息:

[{
  "idMeeting":1,
  "dateTime":"2017-06-21T19:00:00.531",
  "idRoom":1,
  "idPerson":1,
  "participants":[{
     "idPerson":1,
     "firstname":"name",
     "lastname":"name",
     "phonenumber":"0123456789",
     "mailadress":"lars.name@name.de",
     "idCompany":1
   },{
     "idPerson":3,
     "firstname":"Marvin",
     "lastname":"name",
     "phonenumber":"012345678910",
     "mailadress":"Marvin.name@name.de",
     "idCompany":1
  }]
},{
  "idMeeting":2,
  "dateTime":"2017-07-15T17:00:00.531",
  "idRoom":1,
  "idPerson":3,
  "participants":[{
    "idPerson":4,
    "firstname":"Frederic",
    "lastname":"name",
    "phonenumber":"012345678910",
    "mailadress":"Frederik.name@name.de",
    "idCompany":1
  },{
    "idPerson":1,
    "firstname":"Lars",
    "lastname":"name",
    "phonenumber":"0123456789",
    "mailadress":"lars.name@name.de",
    "idCompany":1
  }]
}]

我使用的请求是:

var client = new RestClient("http://myserver");
var request = new RestRequest("project/api/meeting/5", Method.GET);
var response2 = client.Execute<List<Modells.Meeting>>(request);

response2在内容中有json,但数据为空。

我在这里看不到什么错误?

编辑:整个PersonMeeting班级

public class Person
    {
        public int idPerson { get; set; }
        public string firstname { get; set; }
        public string lastname { get; set; }
        public string phonenumber { get; set; }
        public string mailadress { get; set; }
        public int idCompany { get; set; }
     }




 public class Meeting
    {

        public int idMeeting { get; set; }
        public DateTime dateTime { get; set; } // DateTime(Int32, Int32, Int32, Int32, Int32, Int32)  Jahr, Monat, Tag, Stunde, Minute und Sekunde.
        public int idRoom { get; set; }
        public int idPerson { get; set; }
        public List<Person> participants { get; set; }
}

1 个答案:

答案 0 :(得分:1)

感谢mjwills

添加行:

request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

解决了这个问题。看起来这不是正确的json我收到了。