我有以下json格式数据读取问题
我尝试了这个无效的代码,因为Answer节点有一个名为数据的答案
string filePath = Server.MapPath("../App_Data/history.txt");
using (StreamReader r = new StreamReader(filePath))
{
string json = r.ReadToEnd();
List<RootObject> Questions =
JsonConvert.DeserializeObject<List<RootObject>>(json);
public class Answer
{
public string Answer { get; set; }
}
public class Question
{
public string Question { get; set; }
public int CorrectAnswer { get; set; }
public List<Answer> Answers { get; set; }
}
public class RootObject
{
public List<Question> Questions { get; set; }
}
JSON数据:
{
"Questions": [
{
"Question": "Who was the Chola King who brought Ganga from North to South?",
"CorrectAnswer": 1 ,
"Answers": [
{
"Answer": "Raja Raja Chola"
},
{
"Answer": "Rajendra Chola"
},
{
"Answer": "Parantaka"
},
{
"Answer": "Mahendra"
}
]
},
{
"Question": "The writ of 'Habeas Corpus' is issued in the event of:",
"CorrectAnswer": 2 ,
"Answers": [
{
"Answer": "Loss of Property"
},
{
"Answer": "Refund of Excess Taxes"
},
{
"Answer": "Wrongful Police Detention"
},
{
"Answer": "Violation of the Freedom of Speech"
}
]
}
]}