I'm returning a JSON containing an array of objects from an API I made.
[{"Beneficiary":"QaiTS","Total":1000.00,"CurrencyCode":"PHP"}, {"Beneficiary":"MANILEÑOS","Total":4500.00,"CurrencyCode":"PHP"}]
I'm trying to deserialize it with Restsharp's deserializer but when I print out the list, it shows that the properties are empty.
Here's how my code looks like:
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);
Result when I print it on output:
Beneficiary:
CurrencyCode:
Total: 0
Beneficiary:
CurrencyCode:
Total: 0
EDIT: this is what the PaymentSummary class looks like:
public class PaymentSummary
{
public string Beneficiary;
public decimal Total;
public string CurrencyCode;
}
Your class is currently composed of public fields. RestSharp does not deserialize to fields, only public properties. You need to update it to the following:
public class PaymentSummary
{
public string Beneficiary { get; set; }
public decimal Total { get; set; }
public string CurrencyCode { get; set; }
}