[Mono-dev] JSON Deserialization

Adar Wesley adar.wesley at gmail.com
Sun Apr 24 16:11:52 EDT 2011


Hi,

In order to make the code work on MS.NET I had to make the following
changes:
1. mark the class Element with [DataContract] attribute and the Name
property with [DataMember] attribute.
2. Change the serialized JSON to be with double quotes (") and Name should
be quoted too: "[{\"Name\":\"1\"}, {\"Name\":\"2\"}]".

Only after making these changes does it work on MS.NET.

Hope this helps.

---
Adar Wesley


On Sun, Apr 24, 2011 at 8:03 PM, Troy Hamilton <troy.a.hamilton at gmail.com>wrote:

>
> On Sun, Apr 24, 2011 at 8:53 AM, Antoine Cailliau <
> antoinecailliau at gmail.com> wrote:
>
>> Hi folks,
>>
>>
>>  This piece of code fails to work on Mono.
>>
>
>> ("[{Name:'1'}, {Name:'2'}]"));
>>
>>
>> The raised exception is
>>
>>        Unhandled Exception:
>> System.Runtime.Serialization.SerializationException: Deserialization
>> has failed ---> System.Xml.XmlException: Unexpected token: '
>>
>>
> Can you try replacing the single quotes with escaped double quotes and see
> what you get?
>
> "[{Name:\"1\"}, {Name:\"2\"}]"
>
> I've run into a json libraries before that deal with single quotes
> allright, but I believe the standard is to use double quotes.
>
>
> Good luck,
>
> Troy
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110424/9009b456/attachment.html 


More information about the Mono-devel-list mailing list