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.

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.