How do I deserialize this type of data structure

Mrug

This is my JSON:

"Dt": {    
    "20171021": {    
      "abc": "-"    
    },    
    "20171022": {    
      "abc": "-"    
    },    
    "20171023": {    
      "abc": "-"    
    },    
    "20171024": {    
      "abc": "-"    
    },    
    "20171025": {    
      "abc": "-"    
    }
}

The properties inside Dt is all dynamic. They are all dates but in string format. So I am thinking if I would need a List object but how would JSON.Net map this into List? I am thinking of class structure something similar to:

public class Dt
{
    public List<RealDate> RealDates { get; set;}
}

public class RealDate
{
    public string Date{ get; set;} //to hold "20171021"

    public Tuple<string, string> Keys {get; set;} // to hold abc as Key1 and - as Key2
}

Any help is appreciated.

Marc Gravell

That look like there is no Dt, and the thing that currently has a Dt should actually have:

public Dictionary<string, Foo> Dt { get; set;}

where Foo is:

class Foo {
    public string abc {get;set}
}

You would then post-process this to turn the DTO model (the serialization model) into your actual model.

Remember: any time that there is even a minor difference between what the serialized data looks like, and what your domain model looks like: add a DTO model, and just map between them manually. It'll save your sanity.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I convert a structure with a byte slice data type to bytes?

How can I get the length of a generic data structure without knowing the type of data structure it will be?

How do I best duck-type this Go DisjointSets data structure?

How do I further optimize this Data Structure?

How do I deserialize into trait, not a concrete type?

How do I deserialize an array of JSON objects to a C# anonymous type?

How do I subset a list with mixed data type and data structure?

How can I choose what type to deserialize at runtime based on the structure of the json?

How do I, using XStream, serialize/deserialize objects in a type hierarchy?

How do I use an IF type structure in an UPDATE statement?

How can I deserialize a JSON array into a native .net data structure?

How do I fix this data type error?

How do I determine the data type for a program?

How do I create a data structure?

How do I configure Jackson ObjectMapper to deserialize all fields of type Foo into instances of SubclassOfFoo?

How do I deserialize a JSON array without needing a wrapper type?

How do I deserialize a different structured JSON data in Marshmallow?

How do I structure classes to fit this type of gui system?

How do I deserialize nested JSON data into a flattened object?

How do I get data on a hierarchical structure?

How do I check the data structure of this imported data in React

How do I get System.Text.Json to deserialize objects into their original type?

How do I handle this data type

How to deserialize a JSON to generic objects and get the appropriate type based on the data structure in the JSON?

How do I unitize a variable in structure that is of type structure

How Can I deserialize a json into a structure?

How can I serialize and deserialize a private type?

How do I display my array that is of a structure type

How can I deserialize JSON data to this class structure?