How can I make JsonResult return an array of arrays (without field names) rather than an array of objects?

我的未来我决定 提交于 2019-12-05 13:12:32

It sounds like you just need to return a string like this:

var builder = new StringBuilder();
builder.Append("[");
foreach (var item in listOfDateTimes)
    builder.AppendFormat("[{0}, {1}], ", item.Key, item.Value);
var result = builder.ToString().TrimEnd(new char[]{',',' '}) + "]";
return result;

Are these date/value pairs type of System.Web.UI.Pair? If so, you can do this ;

return Json(yourIEnumerable.Select(x => new[] { x.First, x.Second }).ToArray());

It returns the way you want it to be ;

[["\/Date(1255686550232)\/","foo"],["\/Date(1255686550232)\/","bar"]]

Even if they're not type of System.Web.UI.Pair, I'm sure you get the idea.

Your best bet is to write it yourself, but it is a trivial exercise to do.

In my mind, is it worth spending on hour looking for a way to do it, when you can spend 10 minutes and just do the serialization yourself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!