2

Let's say I have a Json object that looks like this:

{
    "Phones": [
        {
            "Phone": {
                "Value": 123,
                "@Type": "Foo"
            }
        }
    ]
}

I want to call JsonConvert.DeserializeXmlNode() but would like the resulting XML to look like this:

<Phones>
    <Phone Type="Foo">123</Phone>
</Phones>

Currently Value is being deserialized to an xml element as a child of Phone, but I want it to be the XML value of Phone. Is there a way to do this using Json.Net, like a special operator that tells it to deserialize it as such, without having to create a custom serializer? Any help is apppreciated.

Arian Motamedi
  • 7,123
  • 10
  • 42
  • 82
  • May be related to this - http://stackoverflow.com/questions/814001/convert-json-to-xml-or-xml-to-json – Sanket Jul 15 '16 at 17:35

1 Answers1

3

I just figured it out. using

"Phone": {
      "@Type": "Foo",
      "#text": 123
 }

gives me the expected result. #text tells it not to create a child element for that value.

Arian Motamedi
  • 7,123
  • 10
  • 42
  • 82