5
Answers

C# how to use parameters reading different parts of a Json output?

Crown Clit

Crown Clit

5d
70
1

Hello. I will need assistance with figuring out how to use parameters to read a different part of a Json file output. My project involves getting a response from coinmarketcap api and getting coin price value. See below sample. This part works fine.

while(sqlReader.Read()) 
{
    dynamic jObj = JsonConvert.DeserializeObject<dynamic>(response);
    decimal jUSDPrice = jObj.data.BTC[0].quote.USD.price;                 
}

Now, my challenge is to use a parameter CoinCode instead of hardcoded BTC so every time sql reader reads new record it will pull our new coin price eg ETH,XRP etc.

How do I use a variable so it looks similar to below?

decimal jUSDPrice = jObj.data.CoinName[0].quote.USD.price;

Your help will be much appreciated.
CC

Answers (5)