C#中Dictionary序列化为Json

来源:互联网 发布:ip欺骗软件 编辑:程序博客网 时间:2024/06/01 20:05

使用LitJson可以序列化Dictionary

public class P {

        public int t;
        public Dictionary<string, string> dic = new Dictionary<string, string>();

}

Dictionary<string, string> testDic = new Dictionary<string, string>();
testDic.Add("aa", "123");
testDic.Add("bb", "sss");
P p = new P();
p.t = 1;
p.dic = testDic;
Debug.Log(JsonMapper.ToJson(p));

输出结果如下:

{"t":1,"dic":{"aa":"123","bb":"sss"}}

0 0
原创粉丝点击