Reputation: 671
I am fetching json data that is apparently not enumerable. My json class looks like this:
public class Bids
{
public int lastUpdateId { get; set; }
public List<List<object>> bids { get; set; }
public List<List<object>> asks { get; set; }
}
Fetching data:
var depth = w.DownloadString("https://api.binance.com/api/v1/depth?symbol=BTCUSDT&limit=20");
var book = JsonConvert.DeserializeObject<Bids>(depth);
And now I want to loop through 'book' and get the bids. How do I do that in a List>?
Edit; With @TheGeneral's help I managed to get this out.
6537.76000000
0.34799400
[]
With this loop
foreach (var bid in book.bids){
foreach (var item in bid)
Console.WriteLine(item);
How do I get only the first value?
Upvotes: 1
Views: 76
Reputation: 81503
var book = JsonConvert.DeserializeObject<Bids>(depth);
foreach(var bid in book.Bids)
foreach(var item in bid)
// blah
foreach(var ask in book.Ask)
foreach(var item in ask)
// blah
Also, object
should probably be double
public List<List<double>> bids { get; set; }
public List<List<double>> asks { get; set; }
How do I get only the first value?
Console.WriteLine(book.Ask.First().First());
Update
foreach(var ask in book.Ask)
Console.WriteLine(ask.First())
Upvotes: 2