我创建了一个aspx页面,我给供应商。他们会以这种格式将json对象传递给我的url。
[{
"count":"2",
"data":[{
"Name": "Pinky",
"number": "91XXXX",
"place": "Mumbai"
},
{
"Name": "Rohan",
"number": "91XXXX",
"place": "Pune"
}]
}]
如何在上面进行消毒。我可以在下面进行消毒
{
"Name": "Pinky",
"number": "91XXXX",
"place": "Mumbai"
}
班级:
public class Student
{
public string Name { get; set; }
public string number { get; set; }
public string place { get; set; }
}
答案 0 :(得分:4)
在这种情况下,使用如下网站非常有用:http://json2csharp.com/ 从json输出创建C#类。
这将告诉您需要围绕Student课程的包装器。所以你有以下
public class Student
{
public string Name { get; set; }
public string number { get; set; }
public string place { get; set; }
}
public class RootObject
{
public string count { get; set; }
public List<Student> data { get; set; }
}
然后您可以反序列化到RootObject
答案 1 :(得分:2)
这也有助于你..
string jstring = "[{\"count\":\"2\",\"data\":[ {\"Name\": \"Pinky\",\"number\": \"91XXXX\",\"place\": \"Mumbai\"},{\"Name\": \"Rohan\",\"number\": \"91XXXX\",\"place\": \"Pune\"} ]}]";
var rootArray = JArray.Parse(jstring);
List<Student> dataList = rootArray[0]["data"].ToObject<List<Student>>();