1
我已使用this有用的JQuery函数序列化嵌套元素。问题是如何使用c#反序列化它。Deserialise使用C#嵌套HTML元素JSon
下面的代码给出
类型System.Collections.Generic.IList`的”定义无参数的构造函数
string json = @"{""root"":{""id"":""main"",""text"":""150px"",""children"":
[{""id"":""divcls"",""text"":""50px"",""children"":
[{""id"":""qs1"",""text"":""0px"",""children"":[]}]},
{""id"":""divcls2"",""text"":""50px"",""children"":[]},
{""id"":""divcls3"",""text"":""50px"",""children"":[]}]}}";
IList<Commn.main1> objs = new JavaScriptSerializer()
.Deserialize<IList<Commn.main1>>(json);
string blky = "";
foreach (var item in objs)
{
blky += item.id;
}
Label1.Text = Convert.ToString(blky);
public class main1
{
public string id { get; set; }
public string text { get; set; }
public sub1 children { get; set; }
}
public class sub1
{
public string Qid { get; set; }
public string Qval { get; set; }
}
我的JSON是只有2级别deeep如果解决方案是递归的我怎么能知道元件
的深度顺便说可以类引用本身这样
public class main1
{
public string id { get; set; }
public string text { get; set; }
public main1 children { get; set; }
}
非常感谢配音 –