为什么我的API没有打印到文本框?

时间:2016-04-19 22:34:38

标签: c# json visual-studio restsharp

因此,在了解了如何使API工作之后,我设法将其设置为完美地将数据打印到标签上。现在,当我尝试做同样的事情,但使用不同的API(几乎相同的一个)时,它决定不打印出来,感觉就像我错过了一些代码,它只是我吗?

第一个自动收录器(Update_BTC_Ticker)运行完美,它打印出来应该是,但另一个(Update_BTC_Trades)不想打印出来,我错过了什么?

private void Update_BTC_Ticker(object sender, EventArgs e)
{
    var client = new RestClient("https://btc-e.com/api");
    var request = new RestRequest("2/btc_usd/ticker", Method.GET);
    //request.AddHeader("Key", "46G9R9D6-WJ77XOIP-XH9HH5VQ-A3XN3YOZ-8T1R8I8T");
    request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

    IRestResponse<BtcUsdTicker> response = client.Execute<BtcUsdTicker>(request);

    sellLabel.Text = Convert.ToString(response.Data.ticker.sell);
    buyLabelTrue.Text = Convert.ToString(response.Data.ticker.buy);


}



private void Update_BTC_Trades(object sender, EventArgs e)
{
    var client = new RestClient("https://btc-e.com/api");
    var request = new RestRequest("2/btc_usd/trades", Method.GET);
    //request.AddHeader("Key", "46G9R9D6-WJ77XOIP-XH9HH5VQ-A3XN3YOZ-8T1R8I8T");
    request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

    IRestResponse<BtcTradeTicker> response = client.Execute<BtcTradeTicker>(request);

    textBox1.Text = Convert.ToString(response.Data.tradeTicker.price);


}





public class BtcUsdTicker
{
    public Ticker ticker { get; set; }
}

public class Ticker
{

    public float high { get; set; }
    public float low { get; set; }
    public float avg { get; set; }
    public float vol { get; set; }
    public float vol_cur { get; set; }
    public float last { get; set; }
    public float buy { get; set; }
    public float sell { get; set; }
    public int updated { get; set; }
    public int server_time { get; set; }



}


public class BtcTradeTicker
{
    public tradeTicker tradeTicker { get; set; }
}


public class tradeTicker
{
    public int date { get; set; }
    public double price { get; set; }
    public double amount { get; set; }
    public int tid { get; set; }
    public string price_currency { get; set; }
    public string item { get; set; }
    public string trade_type { get; set; }
}

0 个答案:

没有答案