使用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"}}