反序列化JSON文件时需要动态标头

时间:2018-10-10 13:19:33

标签: c# arrays json datetime

我有一个通过SQL提取的oracle查询,然后将其序列化为JSON文件。该查询具有动态的月份标题。

DateTime mnthdate = DateTime.Now;
String mnth1 = mnthdate.ToString("MMM_yy");
String mnth2 = mnthdate.AddMonths(1).ToString("MMM_yy");

A.LAST_OPRID Last_Updated_By, " +
"G.K_PCNT_MTH_1 " + mnth1 + ", " +
"G.K_PCNT_MTH_2 " + mnth2 + ", " +
"G.K_PCNT_MTH_3 " + mnth3 + ", " +
"G.K_PCNT_MTH_4 " + mnth4 + ", " +
"G.K_PCNT_MTH_5 " + mnth5 + ", " +
"G.K_PCNT_MTH_6 " + mnth6 + ", " +
"G.K_PCNT_MTH_7 " + mnth7 + ", " +
"G.K_PCNT_MTH_8 " + mnth8 + ", " +
"G.K_PCNT_MTH_9 " + mnth9 + ", " +
"G.K_PCNT_MTH_10 " + mnth10 + ", " +
"G.K_PCNT_MTH_11 " + mnth11 + ", " +
"G.K_PCNT_MTH_12 " + mnth12 + 
@" FROM 

所有这些都很好。然后,我需要在将数据反序列化为datagridview时回调这些相同的标头。我不知道是否需要重新定义我的月份,或者是否可以将这些变量从一种形式引用到另一种形式。 查询以表格3进行,一旦进行查询便将其丢弃。 下面是form1

            using (StreamReader file = File.OpenText(@"C:\assign.json"))
        {
            JsonSerializer serializer = new JsonSerializer();
            IEnumerable<AssgnData> movie2 = (IEnumerable<AssgnData>)serializer.Deserialize(file, typeof(IEnumerable<AssgnData>));
            dataGridView1.DataSource = movie2;

            DateTime mnthdate = DateTime.Now;
            String mnth1 = mnthdate.ToString("MMM_yy");
            String mnth2 = mnthdate.AddMonths(1).ToString("MMM_yy");
            String mnth3 = mnthdate.AddMonths(2).ToString("MMM_yy");
            String mnth4 = mnthdate.AddMonths(3).ToString("MMM_yy");
            String mnth5 = mnthdate.AddMonths(4).ToString("MMM_yy");
            String mnth6 = mnthdate.AddMonths(5).ToString("MMM_yy");
            String mnth7 = mnthdate.AddMonths(6).ToString("MMM_yy");
            String mnth8 = mnthdate.AddMonths(7).ToString("MMM_yy");
            String mnth9 = mnthdate.AddMonths(8).ToString("MMM_yy");
            String mnth10 = mnthdate.AddMonths(9).ToString("MMM_yy");
            String mnth11 = mnthdate.AddMonths(10).ToString("MMM_yy");
            String mnth12 = mnthdate.AddMonths(11).ToString("MMM_yy");
        }

    }
    public class AssgnData
    {
        public string PRJ_BU { get; set; }
        public string EMPLID { get; set; }
        public string NAME { get; set; }
        public string mnth1 { get; set; }
        public string mnth2 { get; set; }
    }

0 个答案:

没有答案