循环遍历列表以返回嵌套数组对象c#

时间:2016-03-14 05:08:07

标签: c# asp.net linq asp.net-web-api

我有输出表

*/

我希望像下面那样返回JSON对象

ClientName      Dno     DnoId     Dfull        DfullId
ClientA        AB342A   16711   AB342A-J2015    1
ClientB        AB544A   6648    AB544A-J20131   2
ClientB        AB544A   6648    AB544A-J20151   3
ClientB        AB544A   6648    AB544A-J2015T   4
ClientB        BD944A   6679    BD944A-D20131   5
ClientC        CA778A   12073   CA778A-J20151   6

我用于此输出的类如下

[{  
    "ClientName":"ClientA",
    "DnoList":[  
      {  
        "DnoId":"16711",
        "Dno":"AB342A",
        "DfullList":[  
          {  
            "DfullId":"1",
            "Dfull":"AB342A-J2015"
          }
        ]
      }
    ]
  },
  {  
    "ClientName":"ClientB"
    "DnoList":[  
      {  
        "DnoId":"6648",
        "Dno":"AB544A",
        "DfullList":[  
          {  
            "DfullId":"2",
            "Dfull":"AB544A-J20131"
          },{  
            "DfullId":"3",
            "Dfull":"AB544A-J20151"
          },{  
            "DfullId":"4",
            "Dfull":"AB544A-J2015T"
          }
        ]
      },
      {  
        "DnoId":"6679",
        "Dno":"BD944A",
        "DfullList":[ {  
            "DfullId":"5",
            "Dfull":"BD944A-D20131"
          } ]
      }
    ]
  }]
我正在使用的

和linq查询和类如下

public class MyData
{
    public string ClientName { get; set; }
    public List<DnoList> DnoLists { get; set; }
}

public class DnoList
{
    public int DnoId { get; set; }
    public string Dno { get; set; }
    public List<DfullList> DfullLists { get; set; }
}

public class DfullList
{
    public int DfullId { get; set; }
    public string Dfull { get; set; }
}

但是我被困了,我怎么能循环通过这个添加上面的三个类来制作所需的输出

0 个答案:

没有答案