Вот, пожалуйста:
public ActionResult OpensearchJson(string search)
{
/* returns some domain specific IEnumerable<> of a certain class */
var entities = DoSomeSearching(search);
var names = entities.Select(m => m.Name);
var description = entities.Select(m => m.Description);
var urls = entities.Select(m => m.Url);
var entitiesJson = new object[] { search, names, description, urls };
return Json(entitiesJson, JsonRequestBehavior.AllowGet);
}
ОБНОВЛЕНИЕ:
и для тех, кто не хочет тестировать без фактического хранилища:
public ActionResult OpensearchJson(string search)
{
var entities = new[]
{
new { Name = "Xbox 360", Description = "The official Xbox website from Microsoft", Url = "http://www.xbox.com" },
new { Name = "Xbox cheats", Description = "Codes and walkthroughs", Url = "http://www.example.com/xboxcheatcodes.aspx" },
new { Name = "Xbox 360 games", Description = "Games and accessories", Url = "http://www.example.com/games" },
};
var names = entities.Select(m => m.Name);
var description = entities.Select(m => m.Description);
var urls = entities.Select(m => m.Url);
var entitiesJson = new object[] { search, names, description, urls };
return Json(entitiesJson, JsonRequestBehavior.AllowGet);
}
возврат:
[
"xbox",
[
"Xbox 360",
"Xbox cheats",
"Xbox 360 games"
],
[
"The official Xbox website from Microsoft",
"Codes and walkthroughs",
"Games and accessories"
],
[
"http://www.xbox.com",
"http://www.example.com/xboxcheatcodes.aspx",
"http://www.example.com/games"
]
]
, что в точности соответствует ожидаемому значению JSON.