Hi folks,

I'm trying to convert a JSON list to an IEnumerable list.

This piece of code fails to work on Mono. It should be working with ms
framework. Can someone test it for me ? I don't have the framework on
my computer.

        class Element {
                public string Name { get; set; }
        }
        
        class MainClass
        {       
                public static void Main (string[] args)
                {
                        MemoryStream ms = new 
MemoryStream(Encoding.Unicode.GetBytes
("[{Name:'1'}, {Name:'2'}]"));
                        DataContractJsonSerializer serializer = new
DataContractJsonSerializer(typeof(IEnumerable<Element>));
                        IEnumerable<Element> list = serializer.ReadObject(ms) as
IEnumerable<Element>;
                        ms.Close();
                        
                        Console.WriteLine (list.Count() == 2);
                }
        }

The raised exception is

        Unhandled Exception:
System.Runtime.Serialization.SerializationException: Deserialization
has failed ---> System.Xml.XmlException: Unexpected token: '

If someone have an idea on how to fix it :-)

Antoine
_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to