我正在尝试传递一个我想从jquery访问的Json,
jdata.comType
我的c#代码是,
var frontChartList = new List<object>();
frontChartList.Add(new
{
comType = comType,
today = DateTime.Now.ToString("D"),
agentsAdded = "53",
agentsAvail = "47",
packageAvailDays = leftDays.ToString(),
});
JavaScriptSerializer jss = new JavaScriptSerializer();
String json = jss.Serialize(frontChartList);
return json;
我无法以
的形式访问此内容jdata.comType 只有, jdata [0] .comType
我应该如何创建JSON以获取可以作为jdata.comType访问的字符串? 因为我只会传递一个对象。
答案 0 :(得分:1)
由于您的frontChartList
是List<object>
,请将其更改为单个对象:
var frontChartList = new
{
comType = comType,
today = DateTime.Now.ToString("D"),
agentsAdded = "53",
agentsAvail = "47",
packageAvailDays = leftDays.ToString(),
});