如何在Asp.net mvc 3控制器中创建一个Json对象?

4
  1. How would you create this Json object from my ASP.Net MVC 3 Controller ?
  2. Newbie in Json, in this Json object notation, can I replace the [ and ] sign with { and }?

    var data = [
        {
            label: 'node1',
            children: [
                { label: 'child1' },
                { label: 'child2' }
            ]
        },
        {
            label: 'node2',
            children: [
                { label: 'child3' }
            ]
        }
    ];
    

谢谢

2个回答

2
您可以使用Newtonsoft dll来序列化和反序列化JSON对象。请参阅以下详细信息。

http://james.newtonking.com/

http://json.codeplex.com/

创建 JSON 对象,您需要添加 Newtonsoft.Json dll 并使用以下代码。
 string responseRGCDTO = JsonConvert.SerializeObject(rgcDTO);

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接