예제 #1
0
        static void TestJSONv1()
        {
            t1 ot1 = new t1()
            {
                p1 = 12,
                p2 = "dsfg",
                p3 = new t2 {
                    p1 = DateTime.UtcNow, p2 = "uioziuz"
                },
                p4 = new List <t2> {
                    new t2 {
                        p1 = DateTime.UtcNow.AddDays(12), p2 = "k1"
                    },
                    new t2 {
                        p1 = DateTime.UtcNow.AddDays(7), p2 = "k2"
                    }
                }
            };

            var jsonSet = new Biser.JsonSettings {
                DateFormat = Biser.JsonSettings.DateTimeStyle.ISO
            };

            Biser.JsonEncoder enc = new Biser.JsonEncoder(ot1, jsonSet);
            string            es  = enc.GetJSON(Biser.JsonSettings.JsonStringStyle.Prettify);
            var ot2 = t1.BiserJsonDecode(es, settings: jsonSet);
        }
예제 #2
0
        public JsonDecoder(string encoded, JsonSettings settings = null)
        {
            jsonSettings = (settings == null) ? new JsonSettings() : settings;

            this.encoded = encoded;
            if (encoded == null || encoded.Length == 0)
            {
                return;
            }
            sb  = new StringBuilder();
            len = encoded.Length;
        }
예제 #3
0
            public static t2 BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type
            {
                Biser.JsonDecoder decoder = null;

                if (extDecoder == null)
                {
                    if (enc == null || String.IsNullOrEmpty(enc))
                    {
                        return(null);
                    }
                    decoder = new Biser.JsonDecoder(enc, settings);
                    if (decoder.CheckNull())
                    {
                        return(null);
                    }
                }
                else
                {
                    //JSONSettings of the existing decoder will be used
                    decoder = extDecoder;
                }

                t2 m = new t2();  //!!!!!!!!!!!!!! change return type

                foreach (var props in decoder.GetDictionary <string>())
                {
                    switch (props)
                    {
                    case "p1":
                        m.p1 = decoder.GetDateTime();
                        break;

                    case "p2":
                        m.p2 = decoder.GetString();
                        break;

                    default:
                        decoder.SkipValue();    //MUST BE HERE
                        break;
                    }
                }
                return(m);
            }
예제 #4
0
            public static t1 BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type
            {
                Biser.JsonDecoder decoder = null;

                if (extDecoder == null)
                {
                    if (enc == null || String.IsNullOrEmpty(enc))
                    {
                        return(null);
                    }
                    decoder = new Biser.JsonDecoder(enc, settings);
                    if (decoder.CheckNull())
                    {
                        return(null);
                    }
                }
                else
                {
                    //JSONSettings of the existing decoder will be used
                    decoder = extDecoder;
                }

                t1 m = new t1();  //!!!!!!!!!!!!!! change return type

                foreach (var props in decoder.GetDictionary <string>())
                {
                    switch (props)
                    {
                    case "p1":
                        m.p1 = decoder.GetInt();
                        break;

                    case "p2":
                        m.p2 = decoder.GetString();
                        break;

                    case "p3":
                        m.p3 = t2.BiserJsonDecode(null, decoder);
                        break;

                    case "p4":
                        m.p4 = decoder.CheckNull() ? null : new List <t2>();
                        if (m.p4 != null)
                        {
                            foreach (var el in decoder.GetList())
                            {
                                m.p4.Add(t2.BiserJsonDecode(null, decoder));
                            }
                        }
                        break;

                    default:
                        decoder.SkipValue();    //MUST BE HERE
                        break;
                    }
                }
                return(m);
            }