you can insert data into xml file from json using below code.
[Serializable]
public class LatLong
{
public double? latitude;
public double? longitude;
}
[Serializable]
public class MapView
{
public LatLong center;
public int? zoom;
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string example = "{\"center\":{\"latitude\":\"49.266214\",\"longitude\":\"-122.998577\"},\"zoom\":\"12\"}";
JavaScriptSerializer serializer = new JavaScriptSerializer();
MapView view = serializer.Deserialize<MapView>(example);
ObjectToXml(view,@"E:\Jigar\MyXml.xml");
}
public static void ObjectToXml(object obj, string path_to_xml)
{
//serialize and persist it to it's file
try
{
XmlSerializer ser = new XmlSerializer(obj.GetType());
FileStream fs = File.Open(
path_to_xml,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.ReadWrite);
ser.Serialize(fs, obj);
}
catch (Exception ex)
{
throw new Exception(
"Could Not Serialize object to " + path_to_xml,
ex);
}
}
}
Let me know if you have any problem regarding this...
Jigar Bagadai
reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator