I get data from api from remote service:
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("https://api.coinmarketcap.com/v1/ticker/?limit=1");
HttpContent content = response.Content;
And i have two ways to get data from response:
1)Read data as String
var readContent = await content.ReadAsStringAsync();
2)and Deserialize it:
var desObject = JsonConvert.DeserializeObject>(readContent);
As you see i can Deserialize data just as List< Currency >, and i have the same errors on first and second variant:
Unmapped members were found
Now i do it using foreach loop, but i thing what it's not good idea:
foreach (var i in desObject)
{
//currency.Id = i.Id;
currency.Last_Updated = i.Last_Updated;
currency.Market_Cap_Usd = i.Market_Cap_Usd;
currency.Name = i.Name;
currency.Percent_Change_1h = i.Percent_Change_1h;
currency.Percent_Change_24h = i.Percent_Change_24h;
currency.Percent_Change_7d = i.Percent_Change_7d;
currency.Price_Btc = i.Price_Btc;
currency.Price_Usd = i.Price_Usd;
currency.Rank = i.Rank;
currency.Symbol = i.Symbol;
currency.Total_Supply = i.Total_Supply;
currency.Volume_24h_Usd = i.Volume_24h_Usd;
}
Please tell is it possible to use Automapper in my situation, if no how i can to do it better ?