public async Task <LocalCurrency> GetLocalCurrencyByCountry(string countryName) { var msg = Client.GetStringAsync($"https://restcountries.eu/rest/v2/name/{countryName}"); var msg1 = await msg; LocalCurrency localCurrency = new LocalCurrency(); using (JsonDocument jsonDocument = JsonDocument.Parse(msg1)) { JsonElement root = jsonDocument.RootElement[0]; JsonElement quotes = root.GetProperty("name"); localCurrency.CountryName = quotes.GetString(); localCurrency.CurrencyCode = root.GetProperty("currencies")[0].GetProperty("code").GetString(); localCurrency.CurrencySymbol = root.GetProperty("currencies")[0].GetProperty("symbol").GetString(); } return(localCurrency); }
/// <inheritdoc/> public async Task <LocalCurrency> GetLocalCurrencyByCountry(string countryName) { if (countryName is null) { throw new ArgumentNullException(nameof(countryName)); } using (var client = new HttpClient()) { var responses = await client.GetStringAsync($"{this.currencySource}/name/{countryName}?fields=currencies;name;"); var localCurrencyInfo = JsonSerializer.Deserialize <CurrencyCountryInfo[]>(responses).Last(); var localCurrency = new LocalCurrency() { CountryName = localCurrencyInfo.FullName, CurrencySymbol = localCurrencyInfo.Currencies.First()["symbol"], CurrencyCode = localCurrencyInfo.Currencies.First()["code"], }; return(localCurrency); } }