2013-11-27 61 views
1

如何正確deserialise這個調用的結果JSONArrays(您可以點擊查看輸出):如何正確使用deserialise RestSharp

https://bitpay.com/api/rates

我使用POCO對象是這樣的:

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

而且我調用API,像這樣:

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

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

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

現在,我知道執行的調用是錯誤的,但我該如何解除錯誤?我想要取回一批BitcoinPrice對象。

+1

lolz @「un-wrongify」 –

回答

1

RestSharp不支持反序列化到數組,你可以得到最好的是List<>

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

的原因是,你可以反序列化到需要的類型,讓公衆參數構造函數(由於性能原因大多)。

+0

呃...那比我想象的要容易。非常感謝。 – Avram