1

I am woking (at least trying xD) with DataContractJsonSerializer. I need to Serialize to json a list of Object, so far I have this:

            List<clsPerson> lstPerson = GetSomeDATA
            var jsonData = new List<Object>();

            var lstObjects = new List<Object>();
            lstObjects.AddRange(lstPerson);

            jsonData.Add(new
                {
                    code = "123456789",
                    data = lstObjects
                    //data = new String[] {"123","123"}
                }
            );

            DataContractJsonSerializer dser = new DataContractJsonSerializer(typeof(List<temp>));
            using (MemoryStream ms = new MemoryStream())
            {
                dser.WriteObject(ms, lstObjects);
                String datos = Encoding.Default.GetString(ms.ToArray());
            }   

After this, I am planning to send the serialized data to a WCF service. In fact, first I used this code:

            JavaScriptSerializer ser = new JavaScriptSerializer();
            string datos = ser.Serialize(jsonData);
            datos = datos.Remove(0, 1);
            datos = datos.Remove(datos.Length-1, 1);
            using (var writer = new StreamWriter(request.GetRequestStream()))
            {
                dser.WriteObject(writer.BaseStream, jsonData);
                writer.WriteLine(datos);
            }

But, when I tryed to send it to the Web service, the resultant json string, had (for datatype) this : "CreationDate":"\/Date(-62135596800000)\/".

So, I need some help with DataContractJsonSerializer , so I can send the data in the correct Format. Also any other solutions or suggestions for what I am doing would be welcome.

Thanks

Flezcano
  • 1,647
  • 5
  • 22
  • 39
  • 2
    can you define "correct format"? what you have is valid for the json deserialization agent to know it's a datetime. – Brad Christie Dec 21 '12 at 17:46
  • The date is also correct one...just search stackoverflow for date formatting in json – Bhushan Firake Dec 21 '12 at 17:49
  • 2
    There is no specific date/datetime format in JSON. I'd recommend storing it as a string or seconds (See http://stackoverflow.com/questions/206384/how-to-format-a-json-date) – snurre Dec 21 '12 at 17:55

0 Answers0