We have a Newtonsoft.Json library and two classes.
Class 1:
Public Class SomeClass Private _some_property As String Public Property SomeProperty() As String Get Return _some_property End Get Set(ByVal value As String) _some_property = value End Set End Property End Class Class 2:
Imports Newtonsoft.Json Public Class SomeWrapper Private _items As IList(Of SomeClass) = New List(Of SomeClass) <JsonProperty("Wrapper")> Public Property Items() As IList(Of SomeClass) Get Return _items End Get Set(ByVal value As IList(Of SomeClass)) _items = value End Set End Property End Class And the following client code:
Dim someObj As New SomeClass Dim someWrap As New SomeWrapper someObj.SomeProperty = "blablabla" someWrap.Items.Add(someObj) someWrap.Items.Add(someObj) someWrap.Items.Add(someObj) Dim json As String = JsonConvert.SerializeObject(someWrap, Formatting.Indented) Dim node As XNode = JsonConvert.DeserializeXNode(json, "root") Dim result As String = node.ToString In the json variable we have:
{ "Wrapper": [ { "SomeProperty": "blablabla" }, { "SomeProperty": "blablabla" }, { "SomeProperty": "blablabla" } ] } In the result variable, we have:
<root> <Wrapper> <SomeProperty>blablabla</SomeProperty> </Wrapper> <Wrapper> <SomeProperty>blablabla</SomeProperty> </Wrapper> <Wrapper> <SomeProperty>blablabla</SomeProperty> </Wrapper> </root> The question is how to designate the properties of an object so that they are defined in JSON as XML attributes. That is, SomeProperty should become XML attributes and not nodes.