I wanted to convert the JSON data into XML contains the JSON array entries into the same. JSON data which I am converting is as below
{
"userName":[
"user1",
"user2"
],
"referenceNumber":"098784866589157763",
"responseCode":"00",
"responseDesc":"Success."
}
To convert the JSON to XML using below C# code
XmlDocument doc = JsonConvert.DeserializeXmlNode(jsonData, "response");
which is converting JSON to below XML
<response>
<userName>user1</userName>
<userName>user2</userName>
<referenceNumber>098784866589157763</referenceNumber>
<responseCode>00</responseCode>
<responseDesc>Success.</responseDesc>
</response>
but expected output XML is as below
<response>
<userName>
<element>user1</element>
<element>user2</element>
</userName>
<referenceNumber>098784866589157763</referenceNumber>
<responseCode>00</responseCode>
<responseDesc>Success.</responseDesc>
</response>
Is there any way to achieve the same?
System.Xml.XmlDocumentfamily of APIs and use the modernSystem.Xml.Linq.XDocumentapis that will save you many headaches as you implement your transformation.