JsonConvert.DeserializeXmlNode没有在输出xml中正确嵌套属性

时间:2015-06-15 19:25:57

标签: c# json xml json.net

我有以下JSON字符串,我正在尝试使用JsonConvert.DeserializeXmlNode转换为XML。

    {"Header":
              {"SettingHeaders":
                                [
                                 {"SettingHeaderColumn":{"id":"20","caption":"column1","css":"blue","sortDirection":"2","grouping":"-1"}},
                                 {"SettingHeaderColumn":{"id":"25","caption":"column2","css":"red","sortDirection":"1","grouping":"-1"}}                                    
                                ]  
              }
    }

目前,XML输出如下:

<?xml version="1.0"?>
<Header>
<SettingHeaders>
  <SettingHeaderColumn>
    <id>20</id>
    <caption>column1</caption>
    <css>blue</css>
    <sortDirection>2</sortDirection>
    <grouping>-1</grouping>
 </SettingHeaderColumn>
</SettingHeaders>
<SettingHeaders>
  <SettingHeaderColumn>
    <id>25</id>
    <caption>column2</caption>
    <css>red</css>
    <sortDirection>1</sortDirection>
    <grouping>-1</grouping>
  </SettingHeaderColumn>
</SettingHeaders>
</Header>

但我希望它看起来像:

<?xml version="1.0"?>
<Header>
<SettingHeaders>
  <SettingHeaderColumn>
    <id>20</id>
    <caption>column1</caption>
    <css>blue</css>
    <sortDirection>2</sortDirection>
    <grouping>-1</grouping>
  </SettingHeaderColumn>
  <SettingHeaderColumn>
    <id>25</id>
    <caption>column2</caption>
    <css>red</css>
    <sortDirection>1</sortDirection>
    <grouping>-1</grouping>
  </SettingHeaderColumn>
</SettingHeaders>
</Header>

(不同之处在于SettingHeaders应该包含一个SettingHeaderColumns列表,而不是封装每一个)。我的JSON相对于我想要的XML看起来是不正确的吗?该方法在反序列化时是否出现意外情况?

0 个答案:

没有答案