سؤال

How do I correctly deserialise the results of this call (you can click to see output):

https://bitpay.com/api/rates

I'm using a POCO object like this:

public class BitpayPrice
{
    public string code { get; set; }
    public string name { get; set; }
    public double rate { get; set; }
}

And I'm calling the API like so:

var client = new RestClient();
client.BaseUrl = "https://bitpay.com";

var request = new RestRequest("/api/rates", Method.GET);

var response = client.Execute<BitpayPrice[]>(request);

Now, I know that the call to execute is wrong, but how do I un-wrongify it? I'd like to get back an array of BitcoinPrice objects.

هل كانت مفيدة؟

المحلول

RestSharp doesn't support deserializing into array, the best you can get is a List<>:

var response = client.Execute<List<BitpayPrice>>(request);

The reason is that types that you can deserialize to are required to have public parameterless constructor (for performance reasons mostly).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top