gpt4 book ai didi

c# - 将平面数据转换为分层数据

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:46 25 4
gpt4 key购买 nike

我在 C# 应用程序中获取一些平面数据作为列表。样本数据 google drive spreadsheet

我希望将此数据转换为层次结构。已创建相同 here 的 JSON 表示

我期待的最终结构在这里enter image description here

我已在 C# 中将数据创建为列表。我希望将此列表转换为 C# 集合对象。请给我一些最简单的方法的指示。 [这是一个控制台应用程序代码]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{

public class Marklist
{

public string Student_name { set; get; }
public string Frequency { set; get; }
public string Major { set; get; }
public string Subject_category { set; get; }
public string Subject_subcategory { set; get; }
public int Spring_mark { set; get; }
public int Autumn_mark { set; get; }
public int Summer_mark { set; get; }



public Marklist() { }

public Marklist(string student_name,string frequency,string major,string subject_category,string subject_subcategory,string spring_mark,string autumn_mark,string summer_mark)
{

Student_name =student_name;
Frequency =frequency;
Major =major;
Subject_category =subject_category;
Subject_subcategory =subject_subcategory;
Spring_mark =spring_mark;
Autumn_mark =autumn_mark;
Summer_mark =summer_mark;

}

}

static void Main(string[] args)
{

List<Marklist> Marklists = new List<Marklist>();

Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Monthly",Major="Science",Subject_category="Physics",Subject_subcategory="Atomic",Spring_mark=100,Autumn_mark=95,Summer_mark=75});
Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Monthly",Major="Science", Subject_category="Physics",Subject_subcategory="Nuclear",Spring_mark=95, Autumn_mark=75,Summer_mark=100});
Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Monthly",Major="Science", Subject_category="Physics",Subject_subcategory="Electronics",Spring_mark=75, Autumn_mark=95,Summer_mark=100});
Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Monthly",Major="Language", Subject_category="Tamil",Subject_subcategory="Literature",Spring_mark=80, Autumn_mark=90,Summer_mark=70});
Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Monthly",Major="Commerce" Subject_category="Retail_data",Subject_subcategory="Big_data_analytics",Spring_mark=90, Autumn_mark=80,Summer_mark=70});

Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Weekly",Major="Science",Subject_category="Physics",Subject_subcategory="Atomic",Spring_mark=100,Autumn_mark=95,Summer_mark=75});
Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Weekly",Major="Science", Subject_category="Physics",Subject_subcategory="Nuclear",Spring_mark=95, Autumn_mark=75,Summer_mark=100});
Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Weekly",Major="Science", Subject_category="Physics",Subject_subcategory="Electronics",Spring_mark=75, Autumn_mark=95,Summer_mark=100});
Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Weekly",Major="Language", Subject_category="Tamil",Subject_subcategory="Literature",Spring_mark=80, Autumn_mark=90,Summer_mark=70});
Marklists.Add(new Marklist(){Student_name="Nimalan",Frequency="Weekly",Major="Commerce" Subject_category="Retail_data",Subject_subcategory="Big_data_analytics",Spring_mark=90, Autumn_mark=80,Summer_mark=70});

Marklists.Add(new Marklist(){Student_name="StarNimalan",Frequency="Monthly",Major="Science",Subject_category="Physics",Subject_subcategory="Atomic",Spring_mark=100,Autumn_mark=95,Summer_mark=75});
Marklists.Add(new Marklist(){Student_name="StarNimalan",Frequency="Monthly",Major="Science", Subject_category="Physics",Subject_subcategory="Nuclear",Spring_mark=95, Autumn_mark=75,Summer_mark=100});
Marklists.Add(new Marklist(){Student_name="StarNimalan",Frequency="Monthly",Major="Science", Subject_category="Physics",Subject_subcategory="Electronics",Spring_mark=75, Autumn_mark=95,Summer_mark=100});
Marklists.Add(new Marklist(){Student_name="StarNimalan",Frequency="Monthly",Major="Language", Subject_category="Tamil",Subject_subcategory="Literature",Spring_mark=80, Autumn_mark=90,Summer_mark=70});
Marklists.Add(new Marklist(){Student_name="StarNimalan",Frequency="Monthly",Major="Commerce" Subject_category="Retail_data",Subject_subcategory="Big_data_analytics",Spring_mark=90, Autumn_mark=80,Summer_mark=70});

}
}
}

最佳答案

使用使用 jsonC# 从您的 json 数据创建的此类 # http://json2csharp.com/#

public class Mark
{
public string markname { get; set; }
public int mark { get; set; }
}

public class SubjectSubcategory
{
public string name { get; set; }
public List<Mark> Marks { get; set; }
}

public class SubjectCategory
{
public string name { get; set; }
public List<SubjectSubcategory> Subject_subcategory { get; set; }
}

public class Major
{
public string name { get; set; }
public List<SubjectCategory> Subject_category { get; set; }
}

public class Frequency
{
public string name { get; set; }
public List<Major> Major { get; set; }
}

public class Product
{
public string studentname { get; set; }
public List<Frequency> frequency { get; set; }
}

public class RootObject
{
public List<Product> product { get; set; }
}

关于c# - 将平面数据转换为分层数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com