C# Restsharp反序列化程序返回对象数组的空属性
我将返回一个JSON,其中包含我制作的API中的对象数组。C# Restsharp反序列化程序返回对象数组的空属性,c#,json,restsharp,json-deserialization,C#,Json,Restsharp,Json Deserialization,我将返回一个JSON,其中包含我制作的API中的对象数组。 [{“受益人”:“QaiTS”,“总计”:1000.00,“货币代码”:“PHP”},{“受益人”:“MANILEñOS”,“总计”:4500.00,“货币代码”:“PHP”}] 我试图用Restsharp的反序列化程序对其进行反序列化,但当我打印出列表时,它显示属性为空 下面是我的代码的样子: var client = new RestClient("http://localhost:4000/api/payments/Get
[{“受益人”:“QaiTS”,“总计”:1000.00,“货币代码”:“PHP”},{“受益人”:“MANILEñOS”,“总计”:4500.00,“货币代码”:“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);
public class PaymentSummary
{
public string Beneficiary;
public decimal Total;
public string CurrencyCode;
}
编辑:这是PaymentSummary类的外观:
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);
public class PaymentSummary
{
public string Beneficiary;
public decimal Total;
public string CurrencyCode;
}
您的类当前由公共字段组成。RestSharp不反序列化为字段,只反序列化为公共属性。您需要将其更新为以下内容:
public class PaymentSummary
{
public string Beneficiary { get; set; }
public decimal Total { get; set; }
public string CurrencyCode { get; set; }
}
您的类当前由公共字段组成。RestSharp不反序列化为字段,只反序列化为公共属性。您需要将其更新为以下内容:
public class PaymentSummary
{
public string Beneficiary { get; set; }
public decimal Total { get; set; }
public string CurrencyCode { get; set; }
}
PaymentSummary
的定义是什么?更新了我的问题:)尝试两件事:1)在PaymentSummary
属性中创建字段,2)使用IEnumerable
而不是List
支付摘要的定义是什么?更新了我的问题:)尝试两件事:1)在PaymentSummary
属性中创建字段,2)使用IEnumerable
而不是List