Hi,
as there was a little discussion about serialization of .NET types and
deserialization of these genereted JSON strings I have updated
Ajax.NET Professional (version 6.7.9.1) to allow parsing of new Date
statements, too. You can use the JSON generated string to do a
deserialization right after, now.
I tried to write some other tests to see how these three frameworks
compare when running serialize() and deserialze() methods. JSON.NET
was not able to serialize a simple DateTime instance. When using a
DateTime as property in a class it could be serialized, but
deserializing didn't work because of the wrong date format (which is
different here in Germany and a lot of other countries). Atlas is
working similar to the AjaxPro serialization, but not using UTC.
I started to add more properties/fields to the Person class example to
see which .NET data types are really working?
[AjaxPro.AjaxNoTypeUsage]
public class Person
{
public MyColor color = MyColor.Yellow;
public MyColor2 color2 = MyColor2.Red; // not working with Atlas
public DateTime dt = DateTime.Now;
public float f = 2.3F;
public double d = 1.1;
public int i = 999;
public int[] I = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
public bool b = false;
public char c = '@';
public List<string> s = new List<string>();
public decimal dec = 0.1M;
public string S = "\r\n\t\f\b?{\\r\\n\"\'";
public Person()
{
s.Add("Hello World");
s.Add("öäüÖÄÜ\\'{new Date(12345);[EMAIL PROTECTED]");
s.Add(" ");
}
}
public enum MyColor
{
Black, Red, Yellow, White
}
public enum MyColor2 : byte
{
Black, Red, Yellow, White
}
The class above is only working with AjaxPro. JSON.NET and Atlas have
both problems with non-US formats like dates or the decimal seperator.
Compare following JSON outputs:
Ajax.NET Professional:
{"color":2,"color2":1,"dt":new Date(Date.UTC(2006,6,9,12,18,22,704)),
"f":2.3,"d":1.1,"i":999,"I":[1,2,3,4,5,6,7,8,9],"b":false,"c":"@",
"s":["Hello World","öäüÖÄÜ\\'{new Date(12345);[EMAIL PROTECTED]","
"],
"dec":0.1,"S":"\r\n\t\f\b?{\\r\\n\"'"}
JSON.NET:
{"color":2,"color2":1,"dt":"07/09/2006 14:18:22",
"f":2.3,"d":1.1,"i":999,"I":[1,2,3,4,5,6,7,8,9],"b":false,"c":64,
"s":["Hello World","öäüÖÄÜ\\'{new Date(12345);[EMAIL PROTECTED]","
"],
"dec":"0.1","S":"\r\n\?{\\r\\n\"'"}
Atlas:
{"color":2, MISSING color2!! "dt":new Date(1152454818040),
"f":2.3,"d":1.1,"i":999,"I":[1,2,3,4,5,6,7,8,9],"b":false,"c":"@",
"s":["Hello World","öäüÖÄÜ\\\'{new Date(12345);[EMAIL PROTECTED]","
"],
"dec":0.1,"S":"\r\n\?{\\\r\\n\"\'"}
If you have a deep look in the JSON output you will see a lot of
different serializations. There are some that are ok if the
deserialization is only used for .NET, but using the JSON output in
JavaScript it will very bad if you do not get a real Date object or if
a character is represented as the ASCII code (see JSON.NET that will
serialize the @ sign to 64): The color2 property is using a byte enum
which is not supported by Atlas, I simple removed this for the test
above.
Next, I tried to use the JSON output to create a new instance of the
Person class. Hm, again only Ajax.NET Professional is working correct.
Atlas cannot convert any value with a decimal seperator if it is using
non-US culture info.
--
Best regards | Schöne Grüße
Michael
Microsoft MVP - Most Valuable Professional
Microsoft MCAD - Certified Application Developer
http://weblogs.asp.net/mschwarz/
http://www.schwarz-interactive.de/
mailto:[EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ajax.NET Professional" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/ajaxpro
The latest downloads of Ajax.NET Professional can be found at
http://www.ajaxpro.info
-~----------~----~----~----~------~----~------~--~---