How to convert Json array to list<> c#
[[{
"QID": 1,
"Question": "Question",
"IsMultipel": 0
},
{
"QID": 2,
"Question": "Question",
"IsMultipel": 1
}],
[{
"QID": 1,
"A_ID": 1,
"Answer": "Answer"
},
{
"QID": 1,
"A_ID": 2,
"Answer": "Answer"
},
{
"QID": 1,
"A_ID": 3,
"Answer": "Answer"
},
{
"QID": 1,
"A_ID": 3,
"Answer": "Answer"
}]]
Error:To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that I am doing like:
List<QuestionAndAnswerNewMarge> _QuestionAndAnswerNewMarge = new List<QuestionAndAnswerNewMarge>();
string str="[[{\"QID\":1,\"Question\":\"Question\",\"IsMultipel\":0},{\"QID\":2,\"Question\":\"Question\",\"IsMultipel\":1}],[{\"QID\":1,\"A_ID\":1,\"Answer\":\"Answer\"},{\"QID\":1,\"A_ID\":2,\"Answer\":\"Answer\"},{\"QID\":1,\"A_ID\":3,\"Answer\":\"Answer\"},{\"QID\":1,\"A_ID\":3,\"Answer\":\"Answer\"}]]";
_QuestionAndAnswerNewMarge = JsonConvert.DeserializeObject<List<QuestionAndAnswerNewMarge>>(str).ToList();
public class QuestionAndAnswerNewMarge
{
public List<QuestionNew> QuestionNew { get; set; }
public List<AnswerNew> AnswerNew { get; set; }
}
public class QuestionNew
{
public string QuestionID { get; set; }
public string Question { get; set; }
public string IsMultiple { get; set; }
}
public class AnswerNew
{
public string QuestionID { get; set; }
public string AnswerID { get; set; }
public string Answer { get; set; }
}