ネストされた要素をシリアル化するこの便利な JQuery 関数を使用しました。問題は、C# を使用してデシリアライズする方法です。
次のコードは
'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レベルの深さしかありませんソリューションが再帰的である場合、要素の深さをどのように知ることができますか
ところで、クラスはこのように自分自身を参照できますか
public class main1
{
public string id { get; set; }
public string text { get; set; }
public main1 children { get; set; }
}