C# ASP MVC API IEnumerable JSON数组缺少键名

C# ASP MVC API IEnumerable JSON数组缺少键名,c#,asp.net-mvc,json,C#,Asp.net Mvc,Json,我有一个ASP MVC API控制器,它将IEnumerable数组作为JSON返回 但是我没有得到数组的键名,我得到的只是 [1] 0: { $id: "1" id: 1 itemid: "Flame 19#Bag Acosta Produce Ctn A" descrip: "Flame grape very suite on Carton Box" createdate: "2013-11-17T06:26:50.047" /... 我需要下面清单的钥匙 inventory:[1] 0

我有一个ASP MVC API控制器,它将IEnumerable数组作为JSON返回 但是我没有得到数组的键名,我得到的只是

[1]
0:  {
$id: "1"
id: 1
itemid: "Flame 19#Bag Acosta Produce Ctn A"
descrip: "Flame grape very suite on Carton Box"
createdate: "2013-11-17T06:26:50.047"
/...
我需要下面清单的钥匙

inventory:[1]
0:  {
$id: "1"
id: 1
itemid: "Flame 19#Bag Acosta Produce Ctn A"
descrip: "Flame grape very suite on Carton Box"
createdate: "2013-11-17T06:26:50.047"
/...
代码


感谢您的重播,但我遇到了以下错误:无法将类型“AnonymousType1”隐式转换为“System.Collections.Generic.IEnumerableOops”,我的错误。您应该创建一个类似于public类InventoryData{public IEnumerable Inventory{get;set;}}的类,并更改返回此类型的方法:returnnewinventorydata{Inventory=…};感谢您的重播,但我遇到了以下错误:无法将类型“AnonymousType1”隐式转换为“System.Collections.Generic.IEnumerableOops”,我的错误。您应该创建一个类似于public类InventoryData{public IEnumerable Inventory{get;set;}}的类,并更改返回此类型的方法:returnnewinventorydata{Inventory=…};
public class DtoController : ApiController
{
    private ProduceServiceContext db = new ProduceServiceContext();

    public IEnumerable<InventoryDTO> MapInventories()
    {
        return from i in db.Inventories
        select new InventoryDTO() { id = i.InventoryId, createdate = i.CreateDate ?? DateTime.MinValue, descrip = i.Descriptions,
            itemid = i.ItemDetail, gtin = i.GTIN, lastcost = i.LastCost
/...
return new { inventory = from i in db.Inventories
        select new InventoryDTO() { id = i.InventoryId, createdate = i.CreateDate ?? DateTime.MinValue, descrip = i.Descriptions,
            itemid = i.ItemDetail, gtin = i.GTIN, lastcost = i.LastCost };