I have the following XML file that I need to convert to JSON in the server. Initially I thought I would convert it to a Dictionary and then use the JavaScriptSerializer to turn it into JSON but since each column could have a different value type, I don’t think it would work. Has anyone done something similar before in C#/LINQ?
I need to preserve the Value Types(Boolean, String, Integer) of each column.
I would appreciate any advice on this as Im just starting to work with XML. Thanks.
<Columns>
<Column Name="key1" DataType="Boolean">True</Column>
<Column Name="key2" DataType="String">Hello World</Column>
<Column Name="key3" DataType="Integer">999</Column>
</Columns>
produces:
Obviously this treats all the values as strings. If you want to keep the underlying type semantics you could do the following:
produces:
And if you cannot modify the underlying XML structure you will need a custom function that will convert between your custom types and the underlying .NET type: