110,535
社区成员
发帖
与我相关
我的任务
分享
public class table1
{
public List<table2> ListTable2 {get;set;}
}
public class table2
{
//.....
}
然后转换前先给ListTable2 赋值,之后转换就行了
table1 t1 = new table1();
t1.ListTable2 = ---//这里写你查询操作并赋值给ListTable2
string jsonResult = JsonMapper.ToJson(t1);
Hashtable hash = new Hashtable()
hash["Id"] = id//你从数据库获取的,比如ID,Title
hash["ChildData"]=---//你从数据库获取的子表数据,可以是List,也可以是string等
string jsonResult = JsonMapper.ToJson(hash);