0

I'm Deserialize one XML to one Object, afterwards I serialize this object in one JSON, this process works, but the problem I have with the ouput in json I receive, it's incorrect.. acording with the structure I have..

Because my Root level is missing.., I can't find why, if every is correct?

XML File:

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

c# code:

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 {

Ouput:

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

Ouput I want:

{"Root":{Applications":[{......}]}}
John Kass
  • 25
  • 1
  • 7
  • possible duplicate of [Json.NET serialize object with root name](http://stackoverflow.com/questions/16294963/json-net-serialize-object-with-root-name) – Andrew Whitaker Feb 12 '15 at 17:37
  • @AndrewWhitaker is not a duplicate this case is from json, my case is from xml, and the problem is not serialize the object is deserialize the object with the root, my object is correct, the problem is with JsonConvert.SerializeObject, delete my Root for some reasson.. – John Kass Feb 12 '15 at 17:48
  • 1
    It should not matter that you're deserializing the object from XML. And the problem *is* serializing the object (you're calling `JsonConvert.SerializeObject` after all). The answers in the duplicate will help you solve the problem. – Andrew Whitaker Feb 12 '15 at 17:52

0 Answers0