There is a similar question with the same title, but the solution is not valid for my problem.
I'm trying to serialize the following JSON:
{"Id":1,
"Questions":
[{"Id":"q-1-Q0001","Text":"Volume Too High"},
{"Id":"q-1-Q0002","Text":"Volume Too Low"}],
"Text":"My text."}
With this structure in my C#:
public class Issue
{
public Issue() { Questions = new List<Question>(); }
public string Id { get; set; }
public List<Question> Questions { get; set; }
public string Text { get; set; }
}
public class Question
{
public string Id { get; set; }
public string Text { get; set; }
}
I have JavaScript send a POST with the JSON above to this C# function:
public JsonResult AddIssueToQueue(Issue issue)
{
var id = issue.Id; // Set correctly
var text = issue.Text; // Set correctly
var q = issue.Questions; // NOT set correctly. Set to List of two empty Question items.
}
id and text are set correctly, but q is set to a List that contains two empty Question objects (Id and Text are null in each).
Is my JSON formatted incorrectly? Why doesn't the Questions array propagate correctly?