Question

Is it possible to deserailize a stucture like this.

{
    "name": "Peter Pan",
    "entries": [
        [
            "x",
            {
                "path": "/The Missing Picture/Blog",
            }
        ],
        [
            "y",
            {
                "path": "/the missing picture/Blog/Transformation-Copy.txt",
            }
        ]            
    ],
    "reset": true
}

Into the following class

public class Person
{
    public String Name {get;set;}
    public IDictionary<String, Entry> Entries {get;set;}
}

public class Entry
{
    public String Path {get;set;}
}
Was it helpful?

Solution

It doesn't directly align, no.

Using json2csharp, we can see the equivalent class structure for your JSON.

public class RootObject
{
    public string name { get; set; }
    public List<List<object>> entries { get; set; }
    public bool reset { get; set; }
}

You could deserialize to an object of this structure, then transform your list-of-lists to a dictionary using a LINQ expression.

If you want to match the class structure, you would need JSON that looks like this:

{
    "name": "Peter Pan",
    "entries": [
        {
            "x" :
            {
                "path": "/The Missing Picture/Blog",
            }
        },
        {
            "y" :
            {
                "path": "/the missing picture/Blog/Transformation-Copy.txt",
            }
        }
    ],
    "reset": true
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top