{
"children" : [{
"children" : [{
"children" : [],
"name" : "b"
}
],
"name" : "aaa"
}, {
"children" : [{
"children" : [],
"name" : "t22Name"
}, {
"children" : [],
"name" : "b"
}
],
"name" : "t2"
}
],
"name" : "a"
}

上面的JSON要使用C#生成,自己拼字符串很麻烦,需要一个嵌套类,类很简单:

    class nestedClass
{
public string name { get; set; }
public List<nestedClass> children = new List<nestedClass>();
}

使用示例:

nestedClass t = new nestedClass();
t.name = "a";
nestedClass t1 = new nestedClass();
t1.name = "aaa";
nestedClass t11 = new nestedClass();
t11.name = "b";
t1.children.Add(t11);
t.children.Add(t1);
nestedClass t2 = new nestedClass();
t2.name = "t2";
t.children.Add(t2); nestedClass t22 = new nestedClass();
t22.name = "t22Name";
t2.children.Add(t22);
t2.children.Add(t11);
JSONHelper.WriteJSON(t);

05-02 08:26