JsonConvert序列化对象,缺少根级别

时间:2015-02-12 16:27:19

标签: c# .net xml json json.net

我将一个XML反序列化为一个对象,然后我用一个JSON序列化这个对象,这个过程有效,但是我收到的json中的输出问题,这个问题是错误的...我的结构......

因为我的Root级别缺失..如果每个都是正确的,我无法找到原因?

XML文件:

<?xml version="1.0" encoding="UTF-8" ?>
<Root>
    <Applications>
.....
    </Applications>
</Root>

c#c​​ode:

Root root;

using (StreamReader readerConfig = new StreamReader(appDataXml))
{
root = (Root)serializerConfig.Deserialize(readerConfig);
}

var sz = JsonConvert.SerializeObject(root);

c#Class:

[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class Root {

    private RootApplication[] applicationsField;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayItemAttribute("Application", IsNullable=false)]
    public DashBoardApplication[] Applications {

输出继电器:

{"Applications":[{......}]}

我想要的输出:

{"Root":{Applications":[{......}]}}

0 个答案:

没有答案