zoukankan      html  css  js  c++  java
  • Unity中使用json序列化失败

    • 问题
    //为什么用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类型不支持,所以我们要自己转型以下

      

    1 //Vector3 里面原来是float类型,但是 json 不支持float类型,所以用 double类型
    2 public class Vector3Obj
    3 {
    4      double x;
    5      double y;
    6      double z;
    7 }
    • 使用json的注意事项
    1. - JSON字符串里的非数字型键值没有双引号
    2. - JSON中存在 这样的制表符,看起来和空格一样,但是就是因为它存在校验不通过,需要去掉
    3. - 编辑器有bom头也会造成
  • 相关阅读:
    浮动
    导航
    Json
    节点
    评论框
    WebClient 指定出口 IP
    IIS8 下 JS, CSS 等静态文件出现 500 错误
    使用 ffmpeg 转换 mov 视频
    使用 ildasm 和 ilasm 修改程序集的的引用信息
    2020-01-08 工作日记:无题
  • 原文地址:https://www.cnblogs.com/shingkwan/p/8327554.html
Copyright © 2011-2022 走看看