Beispiel #1
0
        public virtual void Test()
        {
            Debug.LogError("TClass3 test..");

            //Dict<int, int> a = new Dict<int, int>();
            //for (int i = 0; i < 10; i++)
            //{
            //    a.Add(i, i);
            //}
            //foreach (var rItem in a)
            //{
            //    Debug.LogError(rItem.Key + ", " + rItem.Value);
            //}

            // Test JsonNode.ToObject
            //JsonNode rNode = JsonParser.Parse("{\"C\":2.345, \"B\":[2.1, 2.2] }");
            //Debug.LogError(rNode.ToString());
            //var A1 = HotfixJsonParser.ToObject<A1>(rNode);
            //Debug.LogError(A1.B[0]);
            //var rCovNode = HotfixJsonParser.ToJsonNode(A1);
            //Debug.LogError(rCovNode);

            // Test JsonNode.ToList
            //JsonNode rNode = JsonParser.Parse("[{\"C\":2.345, \"B\":[2.1, 2.2] }, {\"C\":2.346, \"B\":[2.2, 2.3] }]");
            //Debug.LogError(rNode.ToString());
            ////var A1 = JsonParser.ToList<List<A1>, A1>(rNode);
            //var A1 = HotfixJsonParser.ToArray<A1>(rNode);
            //Debug.LogError(A1[1].B[0]);
            //var rCovNode = HotfixJsonParser.ToJsonNode(A1);
            //Debug.LogError(rCovNode);

            // Test JsonNode.ToDict
            JsonNode rNode = JsonParser.Parse("{\"1\": {\"C\":2.345, \"B\":[2.1, 2.2] }, \"2\":{\"C\":2.346, \"B\":[2.2, 2.3] } }");

            Debug.LogError(rNode.ToString());
            var A1 = HotfixJsonParser.ToDict <int, A1>(rNode);

            Debug.LogError(A1[2].B[1]);
            Debug.LogError(A1[1].C);
            var rCovNode = HotfixJsonParser.ToJsonNode(A1);

            Debug.LogError(rCovNode);

            //Debug.LogError("2222");
            //var A1 = JsonMapper.ToObject<A1>(new JsonReader("{\"C\":2.345 }")) as A1;
            //Debug.LogError(A1.C);

            //Debug.LogError(typeof(List<A1>).FullName);
        }
Beispiel #2
0
        public static void Test(string rJsonText)
        {
            //Debug.LogError(rJsonText);
            //var rJsonNode = HotfixJsonParser.Parse(rJsonText);
            //Debug.LogError("xxxx1");
            //var rObj = HotfixJsonParser.ToObject<A>(rJsonNode);
            //Debug.LogError("xxxx2");
            //Debug.LogError(rObj.B1);
            //foreach (var rItem in rObj.E)
            //{
            //    foreach (var rItem1 in rItem.Value)
            //    {
            //        Debug.LogError(rItem1.Value.C);
            //    }
            //}
            //rJsonNode = HotfixJsonParser.ToJsonNode(rObj);
            //Debug.LogError(rJsonNode.ToString());

            var rA = new A()
            {
                B1 = 199,
                B2 = 20000,
                A1 = new List <B> {
                    new B {
                        C = 0.1003f,
                    }, new B {
                        C = 1.332f
                    }
                },
                D = new int[] { 2324, 42, 242 },
                E = new Dictionary <int, List <B> >()
                {
                    { 1, new List <B> {
                          new B {
                              C = 1.0232f
                          }, new B {
                              C = 243243.32f
                          }
                      } },
                    { 2, new List <B> {
                          new B {
                              C = 1.0232f
                          }, new B {
                              C = 243243.32f
                          }
                      } }
                },
                F = new Dictionary <int, Dictionary <int, B> >()
                {
                    { 323, new Dictionary <int, B>()
                      {
                          { 23, new B {
                                C = 3213.23f
                            } }
                      } },
                    { 234, new Dictionary <int, B>()
                      {
                          { 23, new B {
                                C = 3213.23f
                            } }
                      } },
                }
            };
            var rJsonNode = HotfixJsonParser.ToJsonNode(rA);

            Debug.LogError(rJsonNode.ToString());

            var rNewA = HotfixJsonParser.ToObject <A>(rJsonNode);

            Debug.LogError(rNewA.B1);
            foreach (var rItem in rNewA.A1)
            {
                Debug.LogError(rItem.C);
                //foreach (var rItem1 in rItem.Value)
                //{
                //    Debug.LogError(rItem1.C);
                //}
            }
        }
Beispiel #3
0
        public string SerializeToText(object obj)
        {
            var rJsonNode = HotfixJsonParser.ToJsonNode(obj);

            return(rJsonNode.ToString());
        }
Beispiel #4
0
        public object DeserializeFrom(Type type, string str)
        {
            var rJsonNode = HotfixJsonParser.Parse(str);

            return(rJsonNode.ToObject(type));
        }
Beispiel #5
0
        public T DeserializeFrom <T>(string str) where T : HotfixSerializerBinary
        {
            var rJsonNode = HotfixJsonParser.ToJsonNode(str);

            return(rJsonNode.ToObject <T>());
        }
Beispiel #6
0
        public override string ToString()
        {
            var rJsonNode = HotfixJsonParser.ToJsonNode(this);

            return(rJsonNode?.ToString());
        }