I'm trying to deserialize some Json data to a list, however the list returns no data.
An example of the Json string I am using is
{
"sequence":82334,
"bids":
[
["7660","10.02477743",11],
["7600","0.01",1],
["7500","0.01",1]
],
"asks":
[
["7672.57","0.63979186",1],
["7673.64","1",1],
["7678.95","1",1]
]
}
I used json2csharp to generate the object class which gave me
public class ProductOrderBook
{
public int sequence { get; set; }
public List<List<object>> bids { get; set; }
public List<List<object>> asks { get; set; }
}
and this is my method I'm using to deserialize the json
public static async Task<List<ProductOrderBook>> GetProductOrderBook()
{
string ts = GetNonce();
string method = "/products/BTC-USD/book?level=2";
string sig = GetSignature(ts, "GET", method, string.Empty);
List<ProductOrderBook> productOrderBooks;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(baseURL);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("CB-ACCESS-KEY", apiKey);
client.DefaultRequestHeaders.Add("CB-ACCESS-SIGN", sig);
client.DefaultRequestHeaders.Add("CB-ACCESS-TIMESTAMP", ts);
client.DefaultRequestHeaders.Add("CB-ACCESS-PASSPHRASE", passphrase);
client.DefaultRequestHeaders.Add("User-Agent", userAgent);
HttpResponseMessage response = client.GetAsync(method).Result;
string json = await response.Content.ReadAsStringAsync();
productOrderBooks = JsonConvert.DeserializeObject<List<ProductOrderBook>>(json);
}
return await Task.Run(() => productOrderBooks);
}
I am getting valid Json returned in the response string, not sure why the productOrderBooks list has no data. Do I have to create two more object classes to hold the bid and ask data and pass these into
public List<List<object>> bids { get; set; }
public List<List<object>> asks { get; set; }