我正在尝试使用RestSharp的Execute方法查询休息端点并序列化为POCO的一个非常简单的示例.但是,我尝试的所有内容都会产生一个response.Data对象,该对象具有NULL值的所有属性.
这是JSON响应:
{
"Result":
{
"Location":
{
"BusinessUnit": "BTA",
"BusinessUnitName": "CASINO",
"LocationId": "4070",
"LocationCode": "ZBTA",
"LocationName": "Name of Casino"
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试代码
[TestMethod]
public void TestLocationsGetById()
{
//given
var request = new RestRequest();
request.Resource = serviceEndpoint + "/{singleItemTestId}";
request.Method = Method.GET;
request.AddHeader("accept", Configuration.JSONContentType);
request.RootElement = "Location";
request.AddParameter("singleItemTestId", singleItemTestId, ParameterType.UrlSegment);
request.RequestFormat = DataFormat.Json;
//when
Location location = api.Execute<Location>(request);
//then
Assert.IsNotNull(location.LocationId); //fails - all properties are returned null
}
Run Code Online (Sandbox Code Playgroud)
这是我的API代码
public T Execute<T>(RestRequest request) where T : new()
{
var client …Run Code Online (Sandbox Code Playgroud)