Click here to Skip to main content
14,865,273 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How to parse and store json data into XML file as specified in below JSON format

{
"result": [
["id", "name"],
[1, "Peta"],
[2, "Aachara"],
[3, "Aanjangaon"],
[4, "Aanjar"],
[5, "Aathankarai"],
[6, "Abu"],
[7, "Abu Road"],
[8, "Achanta"],
[9, "Addanki"],
[10, "Addavaram"],
[11, "Adipur"],
[12, "Adirampattinam"],
[13, "Adoni"]
]
}

What I have tried:

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream resStream = response.GetResponseStream();

string tempString = null;

int count = 0;

do
{
count = resStream.Read(buf, 0, buf.Length);

if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);

sb.Append(tempString);
}
}
while (count > 0); // any more data to read?

string data = sb.ToString();

/*************************************/
JavaScriptSerializer js = new JavaScriptSerializer();

JavaScriptSerializer ser = new JavaScriptSerializer();

var obj = ser.DeserializeObject(data) as ICollection;

StringBuilder sbxml = new StringBuilder();

sbxml.Append("");

StringWriter sw = new StringWriter();

XmlTextWriter wr = new XmlTextWriter(sw);

wr.WriteStartDocument();

foreach (KeyValuePair<string,> item in obj)
{
sbxml.Append("<" + item.Key + ">");

wr.WriteStartElement(item.Key);

foreach (var i in (item.Value as object[]))
{
foreach (var val in (i as ICollection))
{
sbxml.Append("<" + val + ">");

wr.WriteStartElement(val.ToString());


sbxml.Append(");
wr.WriteEndElement();
}
}

sbxml.Append(");
wr.WriteEndElement();
}

wr.WriteEndDocument();
wr.Flush();
wr.Close();
Posted
Updated 26-Apr-16 20:23pm

1 solution

use this Converting between JSON and XML[^]
add Newtonsoft.Json.dll reference[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900