Json数据读取
我有以下json格式的数据读取问题 我尝试了这段代码,但它不起作用,因为应答节点有应答命名数据Json数据读取,json,c#-4.0,Json,C# 4.0,我有以下json格式的数据读取问题 我尝试了这段代码,但它不起作用,因为应答节点有应答命名数据 string filePath = Server.MapPath("../App_Data/history.txt"); using (StreamReader r = new StreamReader(filePath)) { string json = r.ReadToEnd(); List<RootO
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; }
}
{
"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"
}
]
}
]}