how to de-serialize JSON data in which Timestamp it-self contains fields?

后端 未结 2 972
别跟我提以往
别跟我提以往 2020-12-20 06:39

I am Unable to map the class with the given JSON data:

{
    \"Meta Data\": {
        \"1. Information\": \"Intraday (15min) open, high, low, close prices an         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 06:58

    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 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(json);
    

    Try it online

提交回复
热议问题