0

I have a complex json like this:

    {
    "tests": {
        "test1": {
            "a": "50",
            "b": "60",
            "c": "40,",
            "d": "..",
            "e": "...",
            "f": "..",
            "g": "..",
            "h": "..",
            "i": "..",
            "j": "..",
            "k": "..",
            "l": "..",
            "m": ".."
        },
        "tests2": {
            "a": "..",
            "b": "..",
            "c": "..",
            "d": "..",
            "e": "..",
            "f": ".."
        },
        "tests3": {
            "quiz1": {
                "a": "07.00.25.00,",
                "b": "07.00.04.14,",
                "c": "07.00.00.31"
            },
            "quiz2": {
                "a": "...",
                "b": "...",
                "c": "..."
            },
            "quiz3": {
                "a": "..",
                "b": "..",
                "c": ".."
            }
        }
    }
}

I am converting it into object model and get this:

public class Test1
{
    public string a { get; set; }
    public string b { get; set; }
    public string c { get; set; }
    public string d { get; set; }
    public string e { get; set; }
    public string f { get; set; }
    public string g { get; set; }
    public string h { get; set; }
    public string i { get; set; }
    public string j { get; set; }
    public string k { get; set; }
    public string l { get; set; }
    public string m { get; set; }
}

public class Tests2
{
    public string a { get; set; }
    public string b { get; set; }
    public string c { get; set; }
    public string d { get; set; }
    public string e { get; set; }
    public string f { get; set; }
}

public class Quiz1
{
    public string a { get; set; }
    public string b { get; set; }
    public string c { get; set; }
}

public class Quiz2
{
    public string a { get; set; }
    public string b { get; set; }
    public string c { get; set; }
}

public class Quiz3
{
    public string a { get; set; }
    public string b { get; set; }
    public string c { get; set; }
}

public class Tests3
{
    public Quiz1 quiz1 { get; set; }
    public Quiz2 quiz2 { get; set; }
    public Quiz3 quiz3 { get; set; }
}

public class Tests
{
    public Test1 test1 { get; set; }
    public Tests2 tests2 { get; set; }
    public Tests3 tests3 { get; set; }
}

public class RootObject
{
    public Tests tests { get; set; }
}

and using newsoft.json to convert the json into the object model.

Tests versions = Newtonsoft.Json.JsonConvert.DeserializeObject<Tests>(str);

i would like each json object properties to be a dictionary of property at each object.

I know i could use JsonConvert.DeserializeObject<Dictionary<string, string>>(str); if i had 1 json object but i couldn't find a solution to my case.

ATT
  • 921
  • 3
  • 13
  • 30
  • try to use `JToken` directly instead.. need to do `JToken json = JToken.Parse(myJson);` and then you can access its properties like `json[property-name]`. – Bagus Tesa Dec 27 '18 at 08:06
  • Whats the desire to make it a dictionary? as to put it all into a dictionary at a single layer you would need to go through each object at the .net level and then add it to the dictionary object – Simon Price Dec 27 '18 at 08:07
  • Possible duplicate of [How do I use JSON.NET to deserialize into nested/recursive Dictionary and List?](https://stackoverflow.com/q/5546142/10263) – Brian Rogers Dec 27 '18 at 21:51

0 Answers0