2

I am working on a pretty complex json. I have converted whatever needed till now using JSON.Net, but i am stuck in a part of this json. Following is the snippet of the json which i am unable to resolve.

{
    "name": "BIRTHDATE",
    "path": "BIRTHDATE",
    "locale": "IFA_EN_GB",
    "hasAnswer": true,
    "isSatisfied": false,
    "triggeredLines": [],
    "answers": [
        "100"
    ],
    "validationErrors": {
        "100": [
            "Please enter a valid date."
        ],
                "10": [
            "Please enter a valid date."
        ].....
    },
    "definition": null
},

How can i resolve this section.

"validationErrors": {
        "100": [
            "Please enter a valid date."
        ],
                "10": [
            "Please enter a valid date."
        ].....
    }

Class created for deserialization.

public class Question
{
    public string name { get; set; }
    public string path { get; set; }
    public string locale { get; set; }
    public bool hasAnswer { get; set; }
    public bool isSatisfied { get; set; }
    public List<object> triggeredLines { get; set; }
    public List<string> answers { get; set; }
    public object validationErrors { get; set; }
    public object definition { get; set; }
}
8
  • What did you try so far? Please show your code and where specifically you´re stuck. Commented May 24, 2019 at 11:49
  • create a class like this to deserialize. public class Question { public string name { get; set; } public string path { get; set; } public string locale { get; set; } public bool hasAnswer { get; set; } public bool isSatisfied { get; set; } public List<object> triggeredLines { get; set; } public List<string> answers { get; set; } public object validationErrors { get; set; } public object definition { get; set; } } Commented May 24, 2019 at 11:50
  • What do you mean by the dots at the end ?? After the last shown in the second snippet ] Commented May 24, 2019 at 11:53
  • 4
    public Dictionary<string, string[]> validationErrors Commented May 24, 2019 at 12:07
  • 2
    Paste your JSON here.: app.quicktype.io/#l=cs&r=json2csharp The rest it will do on its own. Commented May 24, 2019 at 12:15

1 Answer 1

4

This json:

"validationErrors": {
        "100": [
            "Please enter a valid date."
        ],
                "10": [
            "Please enter a valid date."
        ].....
    }

Is a Dictionary<string,string[]>. so your Question object should have

public Dictionary<string,string[]> validationErrors { get; set; }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.