如何反序列化ff json字符串:
{"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"}
我尝试过代码:
JsonConvert.DeserializeObject<stock>(content);
其中content变量是上面的json字符串。 但是我得到属性的空值。
以下是我的课程:
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; }
}
提前谢谢!
答案 0 :(得分:2)
添加二传手:
公共字符串名称{get;组; }
- 更新 -
您正在将库存清单存入库存。
添加课程:
public class container
{
public List<stock> Stock { get; set; }
public string as_of { get; set; }
}
并致电:
var result = JsonConvert.DeserializeObject<container>(content);
答案 1 :(得分:1)
将此类用于json字符串 -
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; }
}