0

I'm tring to find an example of using json.net to convert a json response to xml. I'm not sure if I should be using LINQ to JSON or XmlNodeConverter or what. Any help would be appreciated.

Nathan
  • 949
  • 1
  • 20
  • 35
  • Duplicate of http://stackoverflow.com/questions/814001/json-net-convert-json-string-to-xml-or-xml-to-json-string – Roy Dictus May 12 '11 at 12:16

2 Answers2

2

http://james.newtonking.com/projects/json/help/

The section 'Converting between JSON and XML' should really help. It has some simple examples.

finoutlook
  • 2,523
  • 5
  • 29
  • 43
0

I've not used json.net but if you have a clr collection you you could use linq to produce the xml for you.

For example:

var xml = 
    new XElement("people",
    from x in personCollection
    orderby x.LastName
    select new XElement("person",
        new XAttribute("personId", x.PersonId),
        new XElement("firstName", x.FirstName),
        new XElement("lastName", x.LastName)))
    );

And an exmple output would be something like:

<people>
    <person ID="1">
        <firstName>first-name-1</firstName>
        <lastName>last-name-1</lastName>
    </person>
    <person ID="2">
        <firstName>first-name-2</firstName>
        <lastName>last-name-2</lastName>
    </person>
    <person ID="1">
        <firstName>first-name-3</name>
        <lastName>last-name-3</lastName>
    </person>
</people>
Craig
  • 6,869
  • 3
  • 32
  • 52