2013-03-19 377 views
0

我在MVC中工作。在我的控制正在创建一个列表在C#中的JSON对象内添加JSON数组#

public class GridColModelLst 
    { 
     List<GridColModel> _items = new List<GridColModel>(); 

     public List<GridColModel> items 
     { 
      get { return _items; } 
      set { _items = value; } 
     } 
    } 


    public class GridColModel 
     { 
      public string name { get; set; } 
      public int? width { get; set; } 
    } 

而且通过这个列表作为JSON的正常工作和我的JSON低于

[{ name: 'Humidity', width: 90}] 

我如何使它像下面的JSON里面添加一个JSON阵列在C#JSON对象

[{ name: 'Humidity', width: 90, searchoptions: { sopt: ['eq', 'ne'] } }] 

由于

====================

更新

在我控制我发送列表像

return Json(Colmodel, JsonRequestBehavior.AllowGet); 

和我得到[{ name: 'Humidity', width: 90}]成功地

我需要的类什么样的变化,以获得一个JSON像

[{ name: 'Humidity', width: 90, searchoptions: { sopt: ['eq', 'ne'] } }] 

回答

1

试试这个:

使用MVC控制器
+0

上午返回JSONRESULT – Peru 2013-03-19 05:48:54

+0

你可以做返回JSON(一些对象)

return Json(new { name = "Humidity", width = 90, searchoptions = new { sopt = new string[] { "eq,nq" } } }, JsonRequestBehavior.AllowGet); 
TGH 2013-03-19 05:56:29

+0

是的,我这样做,N I得到了josn对象。我的questoin是我需要在C#中添加Json数组添加到json对象中的更改。在我的问题中看到我的第二个JSON – Peru 2013-03-19 05:58:53