Click here to Skip to main content
15,885,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
vaScriptSerializer js = new JavaScriptSerializer();
var temp1 = db.aaa.Join(db.bbb, t => SqlFunctions.StringConvert((decimal)t.id).Trim(), t1 => t1.id, (t, t1) => new
            {
                id = t.id,
                text = t.name,
                state = "closed",
                children = new
                {
                    id = t1.id + "1",
                    text = t1.text,
                },
            });
  return js.Serialize(temp1);



this is my linq code, i want use jquery tree generate tree menu in web page.but linq generated data is
HTML
[{"id": 1, "text": "1", "state": "closed","children": {"id": "11","text": "a"}}]
i want generate
C#
[{"id": 1, "text": "1", "state": "closed","children": [{"id": "11","text": "a"}]}]

the json lost one pair of brackets in children node. i want to ask how to modify the linq code to generate right json.
Posted
Updated 28-May-14 19:45pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900