Hej. Próbuję uzyskać konkretne dane z API, chciałbym otrzymać kurs bitcoina.. Oto plik JSON api którego używam:
https://pastebin.com/M3G0mWyt
Oto mój kod:
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace CryptoApiTest
{
class Program
{
HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
Program program = new Program();
await program.getBtcData();
}
private async Task getBtcData()
{
string response = await client.GetStringAsync("Tutaj link do api z moim kluczem");
Datum datum = JsonConvert.DeserializeObject<Datum>(response);
Console.WriteLine(datum.price);
}
}
public class Config
{
public string data { get; set; }
public string symbol { get; set; }
}
public class Usage
{
public int day { get; set; }
public int month { get; set; }
}
public class Datum
{
public int id { get; set; }
public string name { get; set; }
public string symbol { get; set; }
public float price { get; set; }
public int price_btc { get; set; }
public long market_cap { get; set; }
public float percent_change_24h { get; set; }
public float percent_change_7d { get; set; }
public float percent_change_30d { get; set; }
public float volume_24h { get; set; }
public string max_supply { get; set; }
public Timesery[] timeSeries { get; set; }
public int social_dominance_calc_24h_previous { get; set; }
public int social_contributors_calc_24h_previous { get; set; }
public int url_shares_calc_24h_previous { get; set; }
public int tweet_spam_calc_24h_previous { get; set; }
public int news_calc_24h_previous { get; set; }
public float average_sentiment_calc_24h_previous { get; set; }
public int social_score_calc_24h_previous { get; set; }
public int social_volume_calc_24h_previous { get; set; }
public int alt_rank_30d_calc_24h_previous { get; set; }
public int alt_rank_calc_24h_previous { get; set; }
public int social_dominance_calc_24h { get; set; }
public int social_dominance_calc_24h_percent { get; set; }
public int social_contributors_calc_24h { get; set; }
public float social_contributors_calc_24h_percent { get; set; }
public int url_shares_calc_24h { get; set; }
public float url_shares_calc_24h_percent { get; set; }
public int tweet_spam_calc_24h { get; set; }
public float tweet_spam_calc_24h_percent { get; set; }
public int news_calc_24h { get; set; }
public float news_calc_24h_percent { get; set; }
public float average_sentiment_calc_24h { get; set; }
public float average_sentiment_calc_24h_percent { get; set; }
public int social_score_calc_24h { get; set; }
public float social_score_calc_24h_percent { get; set; }
public int social_volume_calc_24h { get; set; }
public float social_volume_calc_24h_percent { get; set; }
public int asset_id { get; set; }
public int time { get; set; }
public float open { get; set; }
public float high { get; set; }
public float low { get; set; }
public float volume { get; set; }
public int url_shares { get; set; }
public int unique_url_shares { get; set; }
public int tweets { get; set; }
public int tweet_spam { get; set; }
public int tweet_followers { get; set; }
public int tweet_quotes { get; set; }
public int tweet_retweets { get; set; }
public int tweet_replies { get; set; }
public int tweet_favorites { get; set; }
public int tweet_sentiment1 { get; set; }
public int tweet_sentiment2 { get; set; }
public int tweet_sentiment3 { get; set; }
public int tweet_sentiment4 { get; set; }
public int tweet_sentiment5 { get; set; }
public int tweet_sentiment_impact1 { get; set; }
public int tweet_sentiment_impact2 { get; set; }
public int tweet_sentiment_impact3 { get; set; }
public int tweet_sentiment_impact4 { get; set; }
public int tweet_sentiment_impact5 { get; set; }
public int social_score { get; set; }
public float average_sentiment { get; set; }
public int sentiment_absolute { get; set; }
public int sentiment_relative { get; set; }
public int news { get; set; }
public float price_score { get; set; }
public int social_impact_score { get; set; }
public int correlation_rank { get; set; }
public float galaxy_score { get; set; }
public float volatility { get; set; }
public int alt_rank { get; set; }
public int alt_rank_30d { get; set; }
public int market_cap_rank { get; set; }
public int percent_change_24h_rank { get; set; }
public int volume_24h_rank { get; set; }
public int social_volume_24h_rank { get; set; }
public int social_score_24h_rank { get; set; }
public int social_contributors { get; set; }
public int social_volume { get; set; }
public int social_volume_global { get; set; }
public float social_dominance { get; set; }
public long market_cap_global { get; set; }
public float market_dominance { get; set; }
public int medium { get; set; }
public int youtube { get; set; }
public int reddit_posts { get; set; }
public int reddit_posts_score { get; set; }
public int reddit_comments { get; set; }
public int reddit_comments_score { get; set; }
public string tags { get; set; }
public float close { get; set; }
}
public class Timesery
{
public int asset_id { get; set; }
public int time { get; set; }
public float open { get; set; }
public float close { get; set; }
public float high { get; set; }
public float low { get; set; }
public float volume { get; set; }
public long market_cap { get; set; }
public int url_shares { get; set; }
public int unique_url_shares { get; set; }
public int? reddit_posts { get; set; }
public int? reddit_posts_score { get; set; }
public int? reddit_comments { get; set; }
public int? reddit_comments_score { get; set; }
public int tweets { get; set; }
public int tweet_spam { get; set; }
public int tweet_followers { get; set; }
public int tweet_quotes { get; set; }
public int tweet_retweets { get; set; }
public int tweet_replies { get; set; }
public int tweet_favorites { get; set; }
public int tweet_sentiment1 { get; set; }
public int tweet_sentiment2 { get; set; }
public int tweet_sentiment3 { get; set; }
public int tweet_sentiment4 { get; set; }
public int tweet_sentiment5 { get; set; }
public int tweet_sentiment_impact1 { get; set; }
public int tweet_sentiment_impact2 { get; set; }
public int tweet_sentiment_impact3 { get; set; }
public int tweet_sentiment_impact4 { get; set; }
public int tweet_sentiment_impact5 { get; set; }
public int social_score { get; set; }
public float average_sentiment { get; set; }
public int sentiment_absolute { get; set; }
public int sentiment_relative { get; set; }
public object search_average { get; set; }
public int news { get; set; }
public float price_score { get; set; }
public float social_impact_score { get; set; }
public float correlation_rank { get; set; }
public float galaxy_score { get; set; }
public float volatility { get; set; }
public int alt_rank { get; set; }
public int alt_rank_30d { get; set; }
public int market_cap_rank { get; set; }
public int percent_change_24h_rank { get; set; }
public int volume_24h_rank { get; set; }
public int social_volume_24h_rank { get; set; }
public int social_score_24h_rank { get; set; }
public int? medium { get; set; }
public int? youtube { get; set; }
public int social_contributors { get; set; }
public int social_volume { get; set; }
public int price_btc { get; set; }
public int social_volume_global { get; set; }
public float social_dominance { get; set; }
public long market_cap_global { get; set; }
public float market_dominance { get; set; }
public float percent_change_24h { get; set; }
}
}
Co robię źle? Posiłkowałem się poradnikiem, wcześniej jak robiłem coś podobnego, ale do API z którego otrzymywałem dosłownie dwie zmienne, to wszystko działało w ten sposób poprawnie. Teraz za każdym razem jak uruchomię program, otrzymuję odpowiedź "0". Czym to jest spowodowane?
Myślałem że winą może być to, że próbuję zrobić stringa z floata, ale wcześniej robiłem string z inta i działało poprawnie, to mnie od takiego myślenia 'odciąga'.