Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中的JSON对象中添加JSON数组#_C#_Json - Fatal编程技术网

C# 在C中的JSON对象中添加JSON数组#

C# 在C中的JSON对象中添加JSON数组#,c#,json,C#,Json,我在MVC工作。在我的控制器中,我正在创建一个列表 public class GridColModelLst { List<GridColModel> _items = new List<GridColModel>(); public List<GridColModel> items { get { return _items; } set { _ite

我在MVC工作。在我的控制器中,我正在创建一个列表

 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; }
    }
如何在C中的JSON对象中添加JSON数组,就像下面的JSON一样#

谢谢

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

更新

在我的控制器中,我发送的列表如下

return Json(Colmodel, JsonRequestBehavior.AllowGet);
我成功地得到了
[{name:'weathy',width:90}]

我需要对类进行哪些更改才能获得类似JSON的

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

 return Json(new { name = "Humidity", width = 90, searchoptions = new { sopt = new string[] { "eq,nq" } } }, JsonRequestBehavior.AllowGet);

我使用MVC控制器返回JSONRESULT你可以返回Json(某个对象)是的,我这样做了,我得到了josn对象。我的questoin是我需要在C#中进行的更改,以便在Json对象中添加Json数组。请参阅我问题中的第二个JSON
[{ name: 'Humidity', width: 90, searchoptions: { sopt: ['eq', 'ne'] } }]
 return Json(new { name = "Humidity", width = 90, searchoptions = new { sopt = new string[] { "eq,nq" } } }, JsonRequestBehavior.AllowGet);