I am utilizing an api created by the makers of some software we use to generate forms on our website. These forms can have a variable number of questions/inputs. Looking at output from Swagger when imported to Visual Studio -> Paste JSON as Class, for one of the forms I get:
public class Source
{
public DateTime SubmittedAt { get; set; }
public int UserID { get; set; }
public int FormId { get; set; }
public int Id { get; set; }
public Data Data { get; set; }
}
public class Data
{
public string _1 { get; set; }
public string _2 { get; set; }
public string _3 { get; set; }
public string _4 { get; set; }
}
Where Data is the list of questions.
But if I were to look at another form with a different number of questions, this class would be either shorter or longer. So I guess I'm curious how you would model a class based on json that returns a variable number of items. I'm pretty new to both json and c#.
Per below request, this is what the json that is returned looks like. In this example, there are four questions "Is this a question or a comment?", "First Name", "Last Name", "Enter your question or comment."
{
"Source": [
{
"SubmittedAt": "2021-03-17T08:52:32.16",
"UserID": 24601,
"FormId": 420,
"Id": 777,
"Data": {
"1": "Comment",
"2": "First Name",
"3": "Pseudonym",
"4": "Blah blah blah blah.."
}
}
]
}