how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
问题描述
我无法使用给定的 JSON 数据映射类:
I am Unable to map the class with the given JSON data:
{
"Meta Data": {
"1. Information": "Intraday (15min) open, high, low, close prices and volume",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2018-09-28 15:45:00",
"4. Interval": "15min",
"5. Output Size": "Full size",
"6. Time Zone": "US/Eastern"
},
"Time Series (15min)": {
"2018-09-28 15:45:00": {
"1. open": "114.2800",
"2. high": "114.5600",
"3. low": "114.2400",
"4. close": "114.4800",
"5. volume": "2316251"
},
"2018-09-28 15:30:00": {
"1. open": "114.4450",
"2. high": "114.4500",
"3. low": "114.2600",
"4. close": "114.2900",
"5. volume": "759991"
},
"2018-09-28 15:15:00": {
"1. open": "114.3550",
"2. high": "114.5200",
"3. low": "114.3100",
"4. close": "114.4400",
"5. volume": "515174"
}
}
}
如何创建类结构结构,以便我可以在 c# 中使用 newtonsoft 对上述数据进行反序列化?
How to create class structure structure so that i can de-serialize the above data using newtonsoft in c#?
推荐答案
借助Quicktype 和一些编辑,我创建了这些类:
Using the help of Quicktype and a bit of editing, I created these classes:
public class RootObject
{
[JsonProperty("Meta Data")]
public MetaData MetaData { get; set; }
[JsonProperty("Time Series (15min)")]
public Dictionary<DateTime, TimeSeriesItem> TimeSeries15Min { get; set; }
}
public class MetaData
{
[JsonProperty("1. Information")]
public string The1Information { get; set; }
[JsonProperty("2. Symbol")]
public string The2Symbol { get; set; }
[JsonProperty("3. Last Refreshed")]
public DateTimeOffset The3LastRefreshed { get; set; }
[JsonProperty("4. Interval")]
public string The4Interval { get; set; }
[JsonProperty("5. Output Size")]
public string The5OutputSize { get; set; }
[JsonProperty("6. Time Zone")]
public string The6TimeZone { get; set; }
}
public class TimeSeriesItem
{
[JsonProperty("1. open")]
public string The1Open { get; set; }
[JsonProperty("2. high")]
public string The2High { get; set; }
[JsonProperty("3. low")]
public string The3Low { get; set; }
[JsonProperty("4. close")]
public string The4Close { get; set; }
[JsonProperty("5. volume")]
public long The5Volume { get; set; }
}
你可以像这样反序列化它:
You can deserialize it like so:
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(json);
在线试用
这篇关于如何反序列化时间戳本身包含字段的JSON数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何反序列化时间戳本身包含字段的JSON数据?


- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 使用 rss + c# 2022-01-01