[Mono-dev] JSON Deserialization
Stifu
stifu at free.fr
Sun Apr 24 12:45:53 EDT 2011
I tried it with .NET. It also throws an exception
(System.Runtime.Serialization.InvalidDataContractException).
"Type 'JsonTest.Element' cannot be serialized.
Consider marking it with the DataContractAttribute attribute, and
marking all of its members you want serialized with the
DataMemberAttribute attribute."
Antoine Cailliau wrote:
>
> 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
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
--
View this message in context: http://mono.1490590.n4.nabble.com/JSON-Deserialization-tp3471570p3471716.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
More information about the Mono-devel-list
mailing list