我正在尝试从一个JavaScript插件的数据库向客户端发送一串JSON,以突出显示它返回的状态。 但是,除了我需要的状态信息之外,我还得到了变量名。 无论如何,我可以更正格式,以便它看起来像这样:
{"statesHighilght":["California","Washington","Utah","Utah","Florida","Kansas","Utah"]}我明白了:
["California","Washington","Utah","Utah","Florida","Kansas","Utah"]这是我的控制器代码的样子:
public ActionResult highlight() { var statesHighlight = db.Jobs .Select(r => r.State); return Json(new { statesHighilght }, JsonRequestBehavior.AllowGet); }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. 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);
Pass the enumerable directly to the Json method instead of wrapping it in an anonymous object.
return Json(statesHighlight, JsonRequestBehavior.AllowGet);
更多推荐
发布评论