关于c#:将数据导入列表

To get the data into list

我有两个清单如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
List<object>[] data = new List<object>[4];
List<HMData>[] Data_Content = new List<HMData>[7];
int indexer=0;

And also I have 3 list as LValues,IValues and BValues each containing 28 data values as follows

LValues={L1,L2,L3....L28},
IValues={I1,I2,I3...I28},
BValues={B1,B2,B3....B28},

foreach (var item in Read_xml_for_childobjects_id.Root.Descendants("object")) //  Contains 4 Items
  {
 for (int k = 0; k < 7; k++)
     {
       Data_Content[k] = new List<HMData>();
       Value_LfromList = LValues.ElementAt(k);
       Value_IfromList = IValues.ElementAt(k);
       Value_BfromList = BValues.ElementAt(k);

       Data_Content[k].Add(new HMData { x = Value_LfromList, y = Value_IfromList, z = Value_BfromList });
      }  
      data[indexer] = new List<object>(Data_Content);
      indexer++;
  }

现在我想输出如下,

1
2
3
4
data=[{L1,I1,B1},{L2,I2,B2},{L3,I3,B3},{L4,L4,B4},{L5,I5,B5},{L6,I6,B6},{L7,I7,B7}],
data=[{L8,I8,B8},{L9,I9,B9},{L10,I10,B10},{L11,I11,B11},{L12,I12,B12},{L13,I13,B13},{L14,I14,B14}],
data=[{L15,I15,B15},{L16,I16,B16},{L17,I17,B17},{L18,I18,B18},{L19,I19,B19},{L20,I20,B20},{L21,I21,B21}],
data=[{L22,I22,B22},{L23,I23,B23},{L24,I24,B24},{L25,I25,B25},{L26,I26,B26},{L27,I27,B27}{L28,I28,B28}].

现在,如果在for循环中为k,如果我把条件取为for (int k = 0; k < 7; k++),那么我得到如下的输出:

1
2
3
4
data=[{L1,I1,B1},{L2,I2,B2}.....{L7,I7,B7}],
data=[{L1,I1,B1},{L2,I2,B2}.....{L7,I7,B7}],
data=[{L1,I1,B1},{L2,I2,B2}.....{L7,I7,B7}],
data=[{L1,I1,B1},{L2,I2,B2}.....{L7,I7,B7}],

因为每次循环运行时它只遇到列表的前7个元素

如果我把循环作为(int k = 0; k < 28; k++)的循环,因为我在每个列表中总共有28个元素,那么在数据内容列表中填入7个元素之后,因为这是我想要的,当遇到8个元素时,我会得到一个错误,因为

1
Index was outside of bounds of the array..

任何帮助都将非常感谢,我知道我已经对同一个问题提出了两个以上的问题,但我怀疑我不能正确地解释我的问题,我希望这个问题是清楚的,

-------更新的问题-------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 for (int k = 0; k < 4; k++)
  {
    for (int l = 0; l < 7; l++)
     {
       Value_LfromList = LValues.ElementAt((k * 7) + l);
       Value_IfromList = IValues.ElementAt((k * 7) + l);
       Value_BfromList = BValues.ElementAt((k * 7) + l);
       Data_Content.Add(new HMData { x = Value_LfromList, y = Value_IfromList, z = Value_BfromList });
            }
        data.Add(Data_Content);
      }
   }

   var data_List = new { data = data };
   var series = new[] { data_List };
   var obj = new {chart,series };
   string result = jSearializer.Serialize(obj);

所以我得到的输出如下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{"chart":{"type":"bubble"},
"series":
   [
      {"data":
         [
           {"x":7,"y":7,"z":49},{"x":7,"y":7,"z":49},{"x":7,"y":9,"z":63},
           {"x":5,"y":9,"z":45},{"x":4,"y":3,"z":12},{"x":2,"y":6,"z":12},
           {"x":3,"y":5,"z":15},{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},
           {"x":7,"y":8,"z":56},{"x":9,"y":6,"z":54},{"x":5,"y":7,"z":35},
           {"x":3,"y":8,"z":24},{"x":4,"y":3,"z":12},{"x":7,"y":8,"z":56},
           {"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},{"x":8,"y":7,"z":56},
           {"x":5,"y":7,"z":35},{"x":3,"y":7,"z":21},{"x":5,"y":8,"z":40},
           {"x":3,"y":7,"z":21},{"x":3,"y":7,"z":21},{"x":5,"y":2,"z":10},
           {"x":5,"y":2,"z":10},{"x":8,"y":6,"z":48},{"x":7,"y":3,"z":21},
           {"x":6,"y":7,"z":42}
         ]
      }
   ]
 }

现在我想要的输出如下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{"chart":{"type":"bubble"},
"series":
   [
      {"data":
         [
           {"x":7,"y":7,"z":49},{"x":7,"y":7,"z":49},{"x":7,"y":9,"z":63},
           {"x":5,"y":9,"z":45},{"x":4,"y":3,"z":12},{"x":2,"y":6,"z":12},
           {"x":3,"y":5,"z":15}],

       "data":
         [
           {"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},
           {"x":9,"y":6,"z":54},{"x":5,"y":7,"z":35},{"x":3,"y":8,"z":24},
           {"x":4,"y":3,"z":12}],

       "data":
         [
           {"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},
           {"x":8,"y":7,"z":56},{"x":5,"y":7,"z":35},{"x":3,"y":7,"z":21},
           {"x":5,"y":8,"z":40}],

        "data":
         [
           {"x":3,"y":7,"z":21},{"x":3,"y":7,"z":21},{"x":5,"y":2,"z":10},
           {"x":5,"y":2,"z":10},{"x":8,"y":6,"z":48},{"x":7,"y":3,"z":21},
           {"x":6,"y":7,"z":42}
         ]
      }
   ]
 }..

我必须把我要转换成JSON格式的数据转换成绘图图,而且数据标签是强制性的…我希望我能解释一下…

-------更新的问题-------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
for (int k = 0; k < 4; k++)
  {
    List<HMData> Data_Content = new List<HMData>();
    for (int l = 0; l < 7; l++)
     {
       Value_LfromList = LValues.ElementAt((k * 7) + l);
       Value_IfromList = IValues.ElementAt((k * 7) + l);
       Value_BfromList = BValues.ElementAt((k * 7) + l);
       Data_Content.Add(new HMData { x = Value_LfromList, y = Value_IfromList, z = Value_BfromList });
     }
     data_list.Add(Data_Content);
   }
   var chart = new
    {
      type = ChartType
    };
   var data = new { data = data_list };
   var series = new[] { data };
   var obj = new {chart,series };
   string result = jSearializer.Serialize(obj);

这是我的输出

1
2
3
4
5
6
7
8
9
10
{"chart":{"type":"bubble"},"series":[{"data":[[{"x":7,"y":7,"z":49},
{"x":7,"y":7,"z":49},{"x":7,"y":9,"z":63},{"x":5,"y":9,"z":45},{"x":4,"y":3,"z":12},
 {"x":2,"y":6,"z":12},{"x":3,"y":5,"z":15}],
[{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},
 {"x":7,"y":8,"z":56},{"x":9,"y":6,"z":54},{"x":5,"y":7,"z":35},{"x":3,"y":8,"z":24},
 {"x":4,"y":3,"z":12}],
[{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},
 {"x":8,"y":7,"z":56},{"x":5,"y":7,"z":35},{"x":3,"y":7,"z":21},{"x":5,"y":8,"z":40}],
[{"x":3,"y":7,"z":21},{"x":3,"y":7,"z":21},{"x":5,"y":2,"z":10},{"x":5,"y":2,"z":10},
 {"x":8,"y":6,"z":48},{"x":7,"y":3,"z":21},{"x":6,"y":7,"z":42}]]}]}

--------更新了所需的输出-------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{"chart":{"type":"bubble"},"series":[
{"data":[[{"x":7,"y":7,"z":49},
{"x":7,"y":7,"z":49},{"x":7,"y":9,"z":63},{"x":5,"y":9,"z":45},{"x":4,"y":3,"z":12},
 {"x":2,"y":6,"z":12},{"x":3,"y":5,"z":15}],

"data":[{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},
 {"x":7,"y":8,"z":56},{"x":9,"y":6,"z":54},{"x":5,"y":7,"z":35},{"x":3,"y":8,"z":24},
 {"x":4,"y":3,"z":12}],


 "data":[{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},{"x":7,"y":8,"z":56},
 {"x":8,"y":7,"z":56},{"x":5,"y":7,"z":35},{"x":3,"y":7,"z":21},{"x":5,"y":8,"z":40}],


 "data":[{"x":3,"y":7,"z":21},{"x":3,"y":7,"z":21},{"x":5,"y":2,"z":10},{"x":5,"y":2,"z":10},
 {"x":8,"y":6,"z":48},{"x":7,"y":3,"z":21},{"x":6,"y":7,"z":42}]]}]}

我希望数据字与JSON输出中的每个数据列表一起提供…哪个不来了……