-4

当我使用 Postman 发出请求时,我得到:

在此处输入图像描述

这是我所期待的:

public class Result<TResultType>
{
    public int? ErrorId { get; protected set; } // Todo: Use it!!!
    public bool Success { get; protected set; }
    public ResponseErrorType ErrorType { get; protected set; }
    public string Message { get; protected set; }
    public TResultType Data { get; protected set; }
}

在这种情况下,TResultType 是:

public class SettingsResponse : BaseResponse
{
    public string LocationCode { get; set; }
    public string Ip { get; set; }
    public int Port { get; set; }
    public string ApplicationPrinterName { get; set; }
    public string MerchantNumber { get; set; }
    public string MessageControl { get; set; }
    public string PRIN { get; set; }
    public string SoftwareName { get; set; }
    public string SoftwareVersion { get; set; }
    public string SystemNumber { get; set; }
}

这就是我执行请求的方式:

using (HttpClient client = GetHttpClient())
{
    var responseTask = client.GetAsync($"{url}/{paramsStr}");
    if (await Task.WhenAny(responseTask, Task.Delay(TimeoutSeconds * 1000)) == responseTask)
    {
        var response = await responseTask;
        return response.IsSuccessStatusCode
            ? await response.Content.ReadAsAsync<Result<TResponse>>()
            : default(Result<TResponse>);
    }

    return Result<TResponse>.FromTimeout();
}

我总是在属性数据中得到空值,即使值在 json 响应中也是如此。

4

1 回答 1

0

属性中具有公共设置器的结果类

public class Result<TResultType>
{
    public int? ErrorId { get; set; } // Todo: Use it!!!
    public bool Success { get; set; }
    public ResponseErrorType ErrorType { get; set; }
    public string Message { get; set; }
    public TResultType Data { get; set; }
}

它现在正在工作。

于 2018-05-07T19:37:03.977 回答