我想将一堆XML文件解析为单个JSON文件,该JSON文件已经在工作。Json在C中使用Json.net格式化#
最终的JSON文件如下所示:
{
"items": [
{
"subItems": [
{
"Name": "Name",
"Value": "Value",
"Type": "text"
},
{
"Name": "Name",
"Value": "Value",
"Type": "text"
}
]
},
{
"subItems": [
{
"Name": "Name",
"Value": "Value",
"Type": "text"
},
{
"Name": "Name",
"Value": "Value",
"Type": "text"
},
...
相反,我要实现以下结构:
{
"items": [
[
{
"Name": "Name",
"Value": "Value",
"Type": "text"
},
{
"Name": "Name",
"Value": "Value",
"Type": "text"
}
],
[
{
"Name": "Name",
"Value": "Value",
"Type": "text"
},
{
"Name": "Name",
"Value": "Value",
"Type": "text"
}
]
]
}
但我不知道怎么做才能确定我的对象这样做,我现在的结构如下:
public class Items
{
public List<Item> items;
}
public class Item
{
public List<SubItem> subItems;
}
public class SubItem
{
public string Name { get; set; }
public string Value { get; set; }
public string Type { get; set; }
}
我应该怎么做?
从列表继承的注意通常被认为是[坏习惯](https://stackoverflow.com/questions/21692193/why-not-inherit-from-listt)。 –
然后直接使用'公开列表<列表>项目';将是最好的解决方案。 –