嵌套JSON对象这是我的JSON:创建从C#模型
[
{
"ChangeFlowsFromParent":"false",
"ChangeFlowsToParent":"true",
"StreamType":"mainine",
"streamName":"ArgOS_2_0",
"Parent":"none",
"Compliance":"Released",
"children":[
{
"ChangeFlowsFromParent":"true",
"ChangeFlowsToParent":"true",
"StreamType":"Release",
"streamName":"ArgOS_2_0_DHAL1",
"Parent":"ArgOS_2_0",
"Compliance":"Released",
"children":[
{
"ChangeFlowsFromParent":"false",
"ChangeFlowsToParent":"true",
"StreamType":"Release",
"streamName":"ArgOS_child_DHAL2",
"Parent":"ArgOS_2_0_DHAL1",
"Compliance":"Released",
"children":[
{
"ChangeFlowsFromParent":"false",
"ChangeFlowsToParent":"true",
"StreamType":"Release",
"streamName":"ArgOS_child_Gen2",
"Parent":"ArgOS_child_DHAL2",
"Compliance":"Released"
}
]
}
]
},
{
"ChangeFlowsFromParent":"true",
"ChangeFlowsToParent":"true",
"StreamType":"Release",
"streamName":"ArgOS_2_0_DHAL2",
"Parent":"ArgOS_2_0",
"Compliance":"NA"
},
{
"ChangeFlowsFromParent":"false",
"ChangeFlowsToParent":"false",
"StreamType":"Release",
"streamName":"ArgOS_2_0_DHAL3",
"Parent":"ArgOS_2_0",
"Compliance":"NA"
}
]
}
]
,这是我的模型
public class TreeModel
{
public string StreamName { get; set; }
public string ParentName { get; set; }
public string StreamType { get; set; }
public bool ChangeFlowsFromParent { get; set; }
public bool ChangeFlowsToParent { get; set; }
public string Compliance { get; set; }
public string Parent { get; set; }
}
所以我在我的模型的形式数据,我需要创建一个像上面提到的那样的嵌套Json结构。 根据parent = streamname,必须创建一个子标记,并将该模型项添加为json数组。
这个JSON是我的树形图。这是如何实现的?
请格式化您的json,它现在是不可读的。 – Glubus
构建一个代表JSON的类,用数据填充类并反序列化它。 –
很抱歉,streamName是primaryKey,并且您希望单个对象具有相同的密钥的所有对象? –