开发者

convert json to xml with json.net

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 LIN开发者_如何学GoQ to JSON or XmlNodeConverter or what. Any help would be appreciated.


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

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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜