我是windows phone8开发的新手。我正在开发需要解析Json的应用程序。请帮我处理这个json数据。
{
"School": [
{
"info": {
"name": "Dary",
"description": "Student",
"startAt": "",
"endAt": "",
"status": "approved",
"type": 7
},
"gui": {
"size": 60,
"sizeMB": "1.7 M"
}
},
{
"info": {
"name": "Henry",
"description": "Student",
"startAt": "",
"endAt": "",
"status": "approved",
"type": 7
},
"gui": {
"size": 60,
"sizeMB": "1.7 M"
}
}
]
}这是class
public class Info
{
public string name { get; set; }
public string description { get; set; }
public string startAt { get; set; }
public string endAt { get; set; }
public string status { get; set; }
public int type { get; set; }
}
public class Gui
{
public int size { get; set; }
public string sizeMB { get; set; }
}
public class School
{
public Info info { get; set; }
public Gui gui { get; set; }
}
public class RootObject
{
public List<School> School { get; set; }
}提前谢谢。
发布于 2015-01-03 15:35:05
正如Peter Torr所建议的,JSON.NET是一个很好的选择。在.net框架中有一个用于序列化的DataContractJsonSerializer,但它不是很健壮。您可以使用Nuget轻松地将JSON.NET添加到您的项目中。将json放在字符串变量中
string json = "<<your json string>>"或从文件中读取
string json = File.ReadAllText("<<path to file>>");然后,下面的代码将反序列化您的文本。
RootObject root = JsonConvert.DeserializeObject<RootObject>(json);如果只保留json数组(方括号[]之间的文本),则可能会丢失根对象(看起来像是从javascript到C#的转换器),然后可以只反序列化该数组。
List<School> school = JsonConvert.DeserializeObject<List<School>>(json);https://stackoverflow.com/questions/27751811
复制相似问题