C# 在C中的JSON对象中添加JSON数组#
我在MVC工作。在我的控制器中,我正在创建一个列表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
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);