Reputation: 5
how can I deserialize the ff json string:
{"stock":[{"name":"stock1","price":{"currency":"AUD","amount":103.50},"percent_change":-1.33,"volume":1583760,"symbol":"SC1"}],"as_of":"2016-06-10T15:20:00+08:00"}
I've tried the code:
JsonConvert.DeserializeObject<stock>(content);
where content variable is the json string above. However I am getting null value of the properties.
Here are my classes:
public class price
{
public string currency { get; }
public double amount { get; }
}
public class stock
{
public string name { get; }
public price price { get; }
public double percent_change { get; }
public int volume { get; }
public string symbol { get; }
}
Thank you in advance!
Upvotes: 0
Views: 108
Reputation:
Add a setter:
public string name { get; set; }
-- update --
You are putting a list of stock into stock.
Add the class:
public class container
{
public List<stock> Stock { get; set; }
public string as_of { get; set; }
}
And call:
var result = JsonConvert.DeserializeObject<container>(content);
Upvotes: 2
Reputation: 19997
Use this class for your json string-
public class Price
{
public string currency { get; set; }
public double amount { get; set; }
}
public class Stock
{
public string name { get; set; }
public Price price { get; set; }
public double percent_change { get; set; }
public int volume { get; set; }
public string symbol { get; set; }
}
public class StockDetails
{
public List<Stock> stock { get; set; }
public string as_of { get; set; }
}
Upvotes: 0