私はこのコードを持っています:
var all_books = db.Books;
var result = all_books.Select(a => new { a.bookid, a.booktitle, a.bookisbn}).Take(4).ToList();
var jsonData = new {
sEcho = param.sEcho,
iTotalRecords = all_assets.Count(),
iTotalDisplayRecords = all_assets.Count(),
aaData = result
};
return Json(jsonData,JsonRequestBehavior.AllowGet);
返される json は次の形式です。
{"sEcho":null,"iTotalRecords":2764,"iTotalDisplayRecords":2764,"aaData":[{"bookid":"M-711745","booktitle":"20844","bookisbn":"HP LA2205wg"},{"bookid":null,"booktitle":"n/a","bookisbn":"n/a"},{"bookid":"M-710587","booktitle":"20707","bookisbn":"HP LA2205wg"},{"bookid":"735129","booktitle":"21272","bookisbn":"HP LA2205wg"}]}
代わりに多次元配列を返したいと思います。
{"sEcho":null,"iTotalRecords":2764,"iTotalDisplayRecords":2764,"aaData":[["bookid":"M-711745","booktitle":"20844","bookisbn":"HP LA2205wg"],["bookid":null,"booktitle":"n/a","bookisbn":"n/a"],["bookid":"M-710587","booktitle":"20707","bookisbn":"HP LA2205wg"],["bookid":"735129","booktitle":"21272","bookisbn":"HP LA2205wg"]]}
私はこのコードを試しました:
var result = all_books.Select(a => new List<string[]>() { new string[]{ a.bookid, a.booktitle, a.bookisbn }}).Take(4);
しかし、私はこのエラーが発生します:
The array type 'System.String[]' cannot be initialized in a query result. Consider using 'System.Collections.Generic.List`1[System.String]' instead.
私は何が欠けていますか?