[英]Remove variable name from JSON data in ASP.NET MVC
I'm trying to send a string of JSON to the client from a database for a JavaScript plugin to highlight the states it gets back. 我正在尝试从数据库中为JavaScript插件向客户端发送JSON字符串,以突出显示其返回的状态。 However, in addition to the state information I need, I'm also getting the variable name.
但是,除了我需要的状态信息之外,我还获得了变量名。 Is there anyway I can correct the formatting so that instead of it looking like this:
无论如何,我可以更正格式,而不是像这样:
{"statesHighilght":["California","Washington","Utah","Utah","Florida","Kansas","Utah"]}
I get this: 我得到这个:
["California","Washington","Utah","Utah","Florida","Kansas","Utah"]
This is what my controller code looks like: 这是我的控制器代码如下所示:
public ActionResult highlight()
{
var statesHighlight =
db.Jobs
.Select(r => r.State);
return Json(new { statesHighilght }, JsonRequestBehavior.AllowGet);
}
将可枚举直接传递给Json
方法,而不是将其包装在匿名对象中。
return Json(statesHighlight, JsonRequestBehavior.AllowGet);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.