Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Convert JSON to XML - C# Routine?

Can someone please provide me C# code on converting JSON to XML. I'm looking to convert somehting like:

{Test:{a:1,b:2,c:{x=3},d:4}}

to

<test a="1" b="2" d="4">
<c x="3" />
</test>

I'm using .NET Framework v1.1 so the Ajax extensions for ASP.NET are no good to me.

Thanks.
[360 byte] By [quantass] at [2007-11-11 10:12:49]
# 1 Re: Convert JSON to XML - C# Routine?
In your situation, I would probably use something like Json.NET ( http://www.newtonsoft.com/products/json/) to deserialize the JSON, then use .NET's standard XmlSerializer to serialize to XML.
Phil Weber at 2007-11-11 23:12:03 >
# 2 Re: Convert JSON to XML - C# Routine?
Hi Phil. Thanks for the info. The only problem i have with Json.net is it is using .NET Framework 2.0. Im using 1.1 within VS .NET 2003. My assembly refuses to reference its DLL. ****.

Any alternatives?
quantass at 2007-11-11 23:13:03 >
# 3 Re: Convert JSON to XML - C# Routine?
Json.NET is open source, right? Couldn't you download the source and and back-port it to .NET 1.1?
Phil Weber at 2007-11-11 23:14:02 >
# 4 Re: Convert JSON to XML - C# Routine?
That would be a good idea but thats the problem. The source is geared towards 2.0 and 2.0 assembly references. Unfortunately my knowledge of 2.0 to 1.1 mapping isnt that extensive.
quantass at 2007-11-11 23:15:12 >