同じタイトルの同様の質問がありますが、解決策は私の問題には有効ではありません。
次の JSON をシリアル化しようとしています。
{"Id":1,
"Questions":
[{"Id":"q-1-Q0001","Text":"Volume Too High"},
{"Id":"q-1-Q0002","Text":"Volume Too Low"}],
"Text":"My text."}
私の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; }
}
上記の JSON を含む POST を JavaScript でこの C# 関数に送信します。
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 と text は正しく設定されていますが、q は 2 つの空の Question オブジェクトを含む List に設定されています (Id と Text はそれぞれ null です)。
JSON の形式が正しくありませんか? Questions配列が正しく伝播しないのはなぜですか?