有没有办法紧凑地将集合序列化为JSON或XML

时间:2017-04-12 10:17:19

标签: c# json xml serialization

我有一组像这样的普通实体:

class Element
{
    public int LongNameOfPropertyA { get; set;}
    public int LongNameOfPropertyB { get; set;}
    public string LongNameOfPropertyC { get; set;}
}

默认情况下,它序列化为:

[{
   "LongNameOfPropertyA": "1",
   "LongNameOfPropertyB": "2",
   "LongNameOfPropertyC": "bla"
},
{
   "LongNameOfPropertyA": "2",
   "LongNameOfPropertyB": "3",
   "LongNameOfPropertyC": "asdf"
}]

我的问题是有一个像这样序列化的选项:

[{
    "entityName": "Element",
    "columns": [ 
        { "columnName": "LongNameOfPropertyA" },
        { "columnName": "LongNameOfPropertyB" },
        { "columnName": "LongNameOfPropertyC" }],
    "data": [
        { "columnData": ["1", "2"]},
        { "columnData": ["2", "3"]},
        { "columnData": ["bla", "asdf"]}]
}]

xml解决方案也是可以接受的

0 个答案:

没有答案