ARTICLE AD BOX
Question closed, final outcome:
public async static void GetCurrencies() { // https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient HttpResponseMessage response = await _client.GetAsync(currenciesUrl); if (!response.IsSuccessStatusCode) { response = await _client.GetAsync(currenciesFallbackUrl); } var jsonReponse = await response.Content.ReadAsStringAsync(); var test = JsonSerializer.Deserialize<Dictionary<string,string>>(jsonReponse); string testQuery = "Mexican Peso"; string testQuery2 = "Bitcoin"; if (test != null) { foreach (var currency in test) { if (currency.Value.Equals(testQuery) || currency.Value.Equals(testQuery2)){ Console.WriteLine("HI"); } } } }Would like to use this API in my group project
https://github.com/fawazahmed0/exchange-api
The fetch link:
https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies.json
and
https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json
It returns this when I fetch countries supported:
{ "1inch": "1inch", "aave": "Aave", "ada": "Cardano", "aed": "Emirati Dirham", "afn": "Afghan Afghani", "akt": "Akash Network", ... }How can I serialize this in C#, I assume theres a better way than for me to write a property for each country.
Tried this and it didnt seem to serialize properly:
public async static void GetCurrencies() { // https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient HttpResponseMessage response = await _client.GetAsync(currenciesUrl); response.EnsureSuccessStatusCode(); var jsonReponse = await response.Content.ReadAsStringAsync(); var test = JsonSerializer.Deserialize<CountriesCurrencyListDTO>(jsonReponse); }My DTO:
public class CountriesCurrencyListDTO { public Dictionary<string, string> CountryCurrencys { get; set; } }