我有JSON中的問題列表。他們每個人都包含答案列表。當我反序列化它時,答案列表不會反序列化。我只是用空的答案清單收到問題。我怎樣才能解決這個問題?
我反序列化反序列化列表Json C中的列表#
List<QuestionTxt> myDeserializedObjList = (List<QuestionTxt>)Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(@"d:\test.txt"), typeof(List<QuestionTxt>));
JSON
[
{
"answers": [
{
"answer": "1",
"text": "First"
},
{
"answer": "Second",
"text": "2"
}
],
"cost": 1.0,
"count": 2,
"image": false,
"imagePath": null,
"name": "Numbers",
"about": "Numbers",
"solve": false,
"type": "Сonformity",
"Id": "cnf0"
},
{
"answers": [
{
"answer": "+",
"text": "One"
},
{
"answer": "-",
"text": "Two"
}
],
"cost": 1.0,
"count": 2,
"image": false,
"imagePath": null,
"name": "Numbers 2",
"about": "Numbers 2",
"solve": false,
"type": "One",
"Id": "rdb0"
}
]
QuestionTxt
回答
class Answer
{
private string text_;
private string answer_;
public Answer(string text, string answer)
{
this.text = text;
this.answer = answer;
}
public string answer { get => answer_; set => answer_ = value; }
public string text { get => text_; set => text_ = value; }
}
顯示'QuestionTxt'類 – Fabio
@Fabio添加QuestionTxt – SummertimeSadness
我們還需要看到答案對象。請將代碼粘貼到您的問題中,請勿鏈接圖片。 –