Click here to Skip to main content
12,398,537 members (57,499 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
My develop platform is Win7,VS.Net 2010,C#.
When I using the fastJSON.JSON to serialize a custom class when the nullable type DateTimeOffset?,it is OK,but when it deserialize the serialized string,the fastJSON throw exception.

the fastJSON ‘s version is v2.0.10.
you can test it,when you define a DateTimeOffset? Property and set a DateTime.Now value.
when use fastJSON.JSON.Instance.ToJSON() method it's ok,but when use fastJSON.JSON.Instance.ToObject() method,it throw a exception:can not convert the type“System.Collections.Generic.Dictionary`2[System.String,System.Object]”to type“System.String”
Posted 8-Dec-12 3:37am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

the test class is like this :
public static class Test
    {
        public static testclass Create()
        {
            RefClass2 oRef = new RefClass2()
            {
                Class2ID = ",id2,",
                Class2Name = "name2"
            };
            RefClass2 oRef2 = new RefClass2()
            {
                Class2ID = "id3",
                Class2Name = "name3"
            };
            RefClass1 oTeacher = new RefClass1()
            {
                Class1ID = "id1",
                Class1Name = "name1",
                Class1ObjType = EnumObj1.A,
                RefClass = oRef
            };
            RefClass1 oTeacher2 = new RefClass1()
            {
                Class1ID = "\"id4\"",
                Class1Name = "name4",
                Class1ObjType = EnumObj1.B,
                RefClass = oRef2
            };
            testclass oRet = new testclass()
            {
                Name = "xiao ming",
                Age = 16,
                ShirtColor = ConsoleColor.Blue,
                Mode = StartMode.Manual,
                PreviewExecuteionTime = null,
                NextExecuteionTime = DateTime.Now,
                Teachers = new RefClass1[2] { oTeacher, oTeacher2 }
            };
            return oRet;
        }
    }
 
    public class testclass
    {
        public string Name { get; set; }
 
        public int Age { get; set; }
 
        public string School { get; private set; }
 
        public ConsoleColor ShirtColor { get; set; }
 
        public StartMode Mode{get;set;}
 
        public string ModeText
        {
            get
            {
                if (Mode == StartMode.Auto)
                {
                    return "0";
                }
                return "1";
            }
        }
 
        public DateTimeOffset? PreviewExecuteionTime { get; set; }
 
        public DateTimeOffset? NextExecuteionTime { get; set; }
 
        public RefClass1[] Teachers { get; set; }
    }
 
    public enum StartMode
    {
        Auto = 0,
        Manual = 1
    }
 
    public class RefClass1
    {
        public string Class1ID { get; set; }
 
        public string Class1Name { get; set; }
 
        public EnumObj1 Class1ObjType { get; set; }
 
        public RefClass2 RefClass { get; set; }
    }
 
    public class RefClass2
    {
        public string Class2ID { get; set; }
 
        public string Class2Name { get; set; }
    }
 
    public enum EnumObj1
    {
        A = 0,
        B = 1
    }

invoke the Test.Create() static method can create a testing object.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100