少年修仙传客户端基础资源
lwb
2021-01-26 f10c768723fda22f62f26833bdaa672baa3dc322
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using LitJson;
using UnityEngine;
 
namespace HotFix_Project
{
    public class TestJson
    {
        enum JsonTestEnum
        {
            Test1,
            Test2,
            Test3,
        }
        class JsonTestClass
        {
            public int IntProp { get; set; }
            public string StringProp { get; set; }
            public JsonTestEnum EnumProp { get; set; }
            public JsonTestSubClass SubClassProp { get; set; }
            public Dictionary<string, JsonTestSubClass> DicTest { get; set; }
            public Dictionary<string, int> DicTest2 { get; set; }
        }
 
        class JsonTestSubClass
        {
            public long LongProp { get; set; }
            public List<JsonTestSubClass> SubClassList { get; set; }
            public JsonTestSubClass[] ArrayProp { get; set; }
        }
 
        public static void RunTest()
        {
            JsonTestClass cls = new JsonTestClass();
            cls.IntProp = 1;
            cls.StringProp = "2";
            cls.EnumProp = JsonTestEnum.Test3;
            var sub = new JsonTestSubClass();
            sub.LongProp = 4;
            var sub2 = new JsonTestSubClass();
            sub2.LongProp = 5;
            var sub3 = new JsonTestSubClass();
            sub3.LongProp = 6;
 
            cls.SubClassProp = sub;
            sub.ArrayProp = new JsonTestSubClass[2];
            sub.ArrayProp[0] = sub2;
            sub.ArrayProp[1] = sub3;
            sub.SubClassList = new List<JsonTestSubClass>();
            sub.SubClassList.Add(sub2);
            sub.SubClassList.Add(sub3);
 
            cls.DicTest = new Dictionary<string, JsonTestSubClass>();
            cls.DicTest["11111"] = sub;
            cls.DicTest2 = new Dictionary<string, int>();
            cls.DicTest2["111222"] = 333444;
 
            var str = JsonMapper.ToJson(cls);
            Debug.Log("---------------");
            Debug.Log(str);
            Debug.Log("---------------");
            var cls2 = JsonMapper.ToObject<JsonTestClass>(str);
            Debug.Log(cls2.SubClassProp.ArrayProp[0].LongProp);
            Debug.Log(cls2.SubClassProp.ArrayProp[1].LongProp);
            Debug.Log(cls2.SubClassProp.SubClassList[0].LongProp);
            Debug.Log(cls2.SubClassProp.SubClassList[1].LongProp);
            Debug.Log(cls2.DicTest["11111"].LongProp);
            Debug.Log(cls2.DicTest2["111222"]);
        }
    }
}