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; }
}
非常感謝配音 –