C# json 数据循环

来源:百度知道 编辑:UC知道 时间:2024/05/28 12:24:33
{
"note":"杨杨 asdfafafds",
"image":{
"url":null,
"border":null,
"height":null,
"width":null
},
"title":"根目录",
"children":[
{
"note":"asffafdsd<br>",
"image":{
"url":null,
"border":null,
"height":null,
"width":null
},
"title":"12212121",
"children":[
],
"putright":"0",
"fold":"0",
"id":"21"
},
{
"note":"第二季备注<br><br>&

(请楼主耐心看完,因为是专门为你的问题写的)

1.首先需要写三个类,这个类和json中对象的数据结构应该是对应的,这里的例子可能忽略了部分属性和数据类型,仅供参考:

//Json数据的对象结构
public class MyJson
{
public List<MyTreeNodeBean> beanList { get; set; }
}

//树形结构中的对象结构
public class MyBean
{
public string id { get; set; }
public string title { get; set; }
public string note { get; set; }
public MyImage image { get; set; }
public string maxid { get; set; }
public string fold { get; set; }
public string putright { get; set; }
public List<MyTreeNodeBean> children { get; set; }

public MyBean()
{
}
}

//对象里面Image的结构
public class MyImage
{
public string url { get; set; }
public string border { get; set; }
public string height { get; set; }
public string width { get; set; }
}

2.因为json是树形结构的数据,所以需要递归遍历去寻找对应ID的对象