[Mono-list] DataContractJsonSerializer Gives Different Results Depending OS
Atsushi Eno
atsushieno at veritas-vos-liberabit.com
Tue Mar 22 20:22:55 EDT 2011
Please rather file a bug on bugzilla so that it don't flow away thanks.
Atsushi Eno
(2011/03/21 1:33), fletcham wrote:
> I have written a small client - server application which passes JSON messages
> back and forth. The computer with the server application is running Windows
> 7 and the client application is on a Mac as well as on the iPhone using
> MonoTouch. When I serialize an object utilizing the
> DataContractJsonSerializer it gives me two different JSON responses
> depending on the OS I am using.
>
> On Windows 7 using mono/.net 3.5 it gives me this result:
>
> [{"Suit":0},{"Suit":1},{"Suit":2}]
>
> On OSX 10.6.5 using mono/.net 3.5 it gives me this result:
>
> [{"__type":"Card:#JsonTest","Suit":0},{"__type":"Card:#JsonTest","Suit":1},{"__type":"Card:#JsonTest","Suit":2}]
>
> Has anyone run into a similar problem or is this to be expected?
>
> I have included a simple console application demonstrating the results
> listed above. For the console application to run you need to include two
> reference: System.Runtime.Serialization and System.ServiceModel.Web. If
> anyone has any input on why this is and how to remedy it, it would be
> greatly appreciated!
>
> Thank you,
> Adam
>
>
> using System;
> using System.Collections.Generic;
> using System.Runtime.Serialization.Json;
> using System.IO;
> using System.Text;
>
> namespace JsonTest
> {
> class MainClass
> {
> public static void Main(string[] args)
> {
> Hand hand = new Hand();
> hand.Add(new Card { Suit = 0 });
> hand.Add(new Card { Suit = 1 });
> hand.Add(new Card { Suit = 2 });
>
> string json;
>
> DataContractJsonSerializer ser = new
> DataContractJsonSerializer(hand.GetType());
> using (MemoryStream ms = new MemoryStream())
> {
> ser.WriteObject(ms, hand);
> json = Encoding.Default.GetString(ms.ToArray());
> }
>
> Console.WriteLine(json);
> }
> }
>
> public class Card
> {
> public int Suit { get; set; }
> }
>
> public class Hand : List
> {
>
> }
> }
>
>
> --
> View this message in context: http://mono.1490590.n4.nabble.com/DataContractJsonSerializer-Gives-Different-Results-Depending-OS-tp3391376p3391376.html
> Sent from the Mono - General mailing list archive at Nabble.com.
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
>
>
More information about the Mono-list
mailing list