Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
0 OriginalGriff 554
1 Gihan Liyanage 338
2 RyanDev 248
3 Sergey Alexandrovich Kryukov 243
4 ChauhanAjay 220
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2014
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