json序列化失败

2017-10-26  本文已影响0人  ShingKwan

问题:

//为什么用json序列化这样没得问题
 Dictionary<string, int> dic = new Dictionary<string, int>();
 dic.Add("1", 1);
 string strJson = LitJson.JsonMapper.ToJson(dic);

//这样有问题 
 Dictionary<int, int> dic2 = new Dictionary<int, int>();
 dic2.Add(1, 1);
 string strJson2 = LitJson.JsonMapper.ToJson(dic2);
 Debug.Log(strJson2);
 

json 序列化时不支持结构体,比如Unity 中的Vector3类型不支持,所以我们要自己转型以下

//Vector3 里面原来是float类型,但是 json 不支持float类型,所以用 double类型
public class Vector3Obj
{
     double x;
     double y;
     double z;
}

使用json的注意事项:

上一篇 下一篇

猜你喜欢

热点阅读