我有一个json对象,该对象返回两个空数组 “子问题”:[] 和“答案”:[]
我已经为该对象创建了类,但是我无法使其正常工作, 这是我到目前为止所拥有的。
对象
"questions": [
{
"questionId": "1",
"question": "Ipsum",
"helpText": null,
"questionType": "MultipleChoice",
"answerChoices": [
{
"answerChoiceId": "b2b-2.01-answer1",
"value": "Lorem",
"subQuestions": []
}
],
"answers": []
}
课程
public class AnswerChoice
{
public string answerChoiceId { get; set; }
public string value { get; set; }
public List<object> subQuestions { get; set; }
}
public class Question
{
public string questionId { get; set; }
public string question { get; set; }
public object helpText { get; set; }
public string questionType { get; set; }
public List<AnswerChoice> answerChoices { get; set; }
public List<object> answers { get; set; }
}
public class ObjectRoot
{
public string productId { get; set; }
public List<Question> questions { get; set; }
}
var jsonBody = new ObjectRoot()
{
productId = productId,
questions = new[]
{
new Question() {
questionId = "b2b-2.01",
question ="Vad är syftet med ert engagemang hos oss?",
helpText = null,
questionType = "MultiChoise",
answerChoices = new []{
new AnswerChoice{
answerChoiceId = "",
value = "",
**HERE is what it gets tricky for me**
}
}
}
}
};
对我来说,最棘手的部分是在value =“”之后,并且需要添加subQuestion对象,它已经尝试了多种方法但没有运气。
答案 0 :(得分:0)
在您的课程中,所有集合都是vid
而不是数组。因此,要使其正常工作,您需要调用List
扩展方法。对于空集合,只需调用ToList
构造函数
List