我有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
我们还需要看到答案对象。请将代码粘贴到您的问题中,请勿链接图片。 –