我正在返回一个包含来自我制作的API的对象数组的JSON。
[{"Beneficiary":"QaiTS","Total":1000.00,"CurrencyCode":"PHP"}, {"Beneficiary":"MANILEÑOS","Total":4500.00,"CurrencyCode":"PHP"}]
我正在尝试使用Restsharp的反序列化器对其进行反序列化,但是当我打印出列表时,它会显示属性为空。
以下是我的代码的样子:
var client = new RestClient("http://localhost:4000/api/payments/GetPaymentSummary");
var request = new RestRequest(Method.GET);
request.RequestFormat = DataFormat.Json;
var response = client.Execute<List<PaymentSummary>>(request);
JsonDeserializer deserialize = new JsonDeserializer();
List<PaymentSummary> list = deserialize.Deserialize<List<PaymentSummary>>(response);
我在输出上打印时的结果:
Beneficiary:
CurrencyCode:
Total: 0
Beneficiary:
CurrencyCode:
Total: 0
编辑:这就是PaymentSummary类的样子:
public class PaymentSummary
{
public string Beneficiary;
public decimal Total;
public string CurrencyCode;
}
答案 0 :(得分:0)
您的课程目前由公共领域组成。 RestSharp不反序列化为字段,仅反向公共属性。您需要将其更新为以下内容:
public class PaymentSummary
{
public string Beneficiary { get; set; }
public decimal Total { get; set; }
public string CurrencyCode { get; set; }
}