XML to JSON

Feb 18, 2009 at 8:52 PM
I have the following nice code in Java which works great. I'm looking for equivalent code in C#. Any help will be greatly appreciated.

String xml = "<xs:complexType name="MyRequest">
<xs:annotation>
<xs:documentation>
 This is the sample message
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element minOccurs="1" name="requestEnvelope"
 type="common:RequestEnvelope" />
<xs:element minOccurs="1" maxOccurs="1"
 name="email" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="transactionId" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="trackingId" type="xs:string"/>
<xs:any maxOccurs="unbounded" minOccurs="0"
 namespace="##other" processContents="lax" />
</xs:sequence>
</xs:complexType>";

JSONObject root = XML.toJSONObject(xml);
Iterator<String> iterator = root.keys();
JSONObject json = root.getJSONObject(iterator.next());

Thanks a lot in advance,

 


Feb 19, 2009 at 7:14 PM
I actually downloaded latest beta version of JSON.NET library and trying to use the APIs but not sure what are the right set of APIs i need to use to get the job done.
I did come across this blog and tried running the sample given at http://ajaxian.com/archives/jsonnet-11-converting-between-xml-and-json.
 I get JavsScriptConvert unknown type. How can i fix this issue?