i need how to insert data to xml file using json coding

Posted by reddysankark-13471 under Others on 9/26/2012 | Points: 10 | Views : 1159 | Status : [Member] | Replies : 4
hi

any body tell me how to insert data to xml file using json coding

sankarreddy


Responses

Posted by: Jigarbagadai on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
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

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

refer this

http://www.dotnetfunda.com/codes/code3273-how-to-insert-data-to-xml-file-using-json-coding.aspx

Mark as Answer if its helpful to you

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Jigarbagadai,

GoodJob

Thanks & Regards
Hari

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response