データテーブルからJSON文字列を作成し、目的のネストされた出力からクラスを生成しました。文字列をネストされたオブジェクトに変換するための背後にあるシャープコードの助けが必要です。このために別注のシリアライザを作成する必要がありますか?より良い方法はありますか?csクラスを使用してフラットファイルをネストJSONに変換する方法
string = [{"name":"example1", "priority" : "high", "PHASE": "phase1","id" :1001, "type": "glove"},
{"name":"example1", "priority" : "high", "PHASE": "phase1","id" :1002, "type": "shoe"},
{"name":"example1", "priority" : "high", "PHASE": "phase1","id" :1003, "type": "sock"},
{"name":"example1", "priority" : "high", "PHASE": "phase2","id" :1005, "type": "large"},
{"name":"example1", "priority" : "high", "PHASE": "phase2","id" :1006, "type": "medium"},
{"name":"example1", "priority" : "high", "PHASE": "phase2","id" :1007, "type": "small"},
{"name":"example1", "priority" : "high", "PHASE": "phase3","id" :1008, "type": "ladies"},
{"name":"example1", "priority" : "high", "PHASE": "phase3","id" :1009, "type": "gents"}];
desired_output = {
"NAME": "example1",
"PRIORITY" : "high",
"PHASE":
{
"phase1":
[
{ "id": "1001", "type": "glove" },
{ "id": "1002", "type": "shoe" },
{ "id": "1003", "type": "sock",
"ph2":
{
"phase2" :
[
{ "id": "1005", "type": "large" },
{ "id": "1006", "type": "medium" },
{ "id": "1007", "type": "small",
"ph3":
{
"phase3":
[
{ "id": "1008", "type": "ladies" },
{ "id": "1009", "type": "gents" }
]}
}
]}
}
]
}
}
public class Phase3
{
public string id { get; set; }
public string type { get; set; }
}
public class Ph3
{
public List<Phase3> phase3 { get; set; }
}
public class Phase2
{
public string id { get; set; }
public string type { get; set; }
public Ph3 ph3 { get; set; }
}
public class Ph2
{
public List<Phase2> phase2 { get; set; }
}
public class Phase1
{
public string id { get; set; }
public string type { get; set; }
public Ph2 ph2 { get; set; }
}
public class PHASE
{
public List<Phase1> phase1 { get; set; }
}
public class RootObject
{
public string NAME { get; set; }
public string PRIORITY { get; set; }
public PHASE PHASE { get; set; }
}
あなたはphがネストされている必要がありますか、別のオブジェクト(階層的にph1> ph2> ph3> ph4か同じレベルのphですか?)をしたいですか? – Tinwor
こんにちは。 ph1> ph2> ph3> ph4である。 – user3359706