1.float转double报错

报错类型:

Max allowed object depth reached while trying to export from type System.Collections.Generic.List

序列化时候会遇到float和double互转问题;

注意这里double转float会导致精度丢失;

解决办法:

JsonMapper.cs中添加几行代码;

2.Dictionary中key为int时报错

报错类型:

InvalidCastException: Specified cast is not valid

原方法中Dictionary的key只支持(string)强转,int强转为string失败,会报错;

解决办法:

JsonMapper.cs中WriteValue方法修改

3.Dictionary中key为enum时报错

LitJson的字典不支持Key为枚举;

序列化不会出错,反序列化会报错,无法读取枚举类型;

解决办法:

修改JsonMapper.cs中ReadValue方法:

原本reader.Value被强转为string,无法识别出枚举;

下面将reader.Value转为Object;

4.Unity中LitJson类型扩展

添加向量Vector2、Vector3、Vector4;

添加四元素Quaternion、Color、Color32;

添加Bounds、Rect、RectOffset;

项目中加入UnityTypeBridge.cs类和JsonExtension.cs类;

代码:

public static class UnityTypeBindings
{
static bool registerd;
static UnityTypeBindings()
{
Register();
}
public static void Register()
{
if (registerd) return;
registerd = true;
// 注册Type类型的Exporter
JsonMapper.RegisterExporter<Type>((v, w) => { w.Write(v.Ful
JsonMapper.RegisterImporter<string, Type>((s) => { return T
// 注册Vector2类型的Exporter
Action<Vector2, JsonWriter> writeVector2 = (v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteObjectEnd();
};
JsonMapper.RegisterExporter<Vector2>((v, w) => { writeVecto
// 注册Vector3类型的Exporter
Action<Vector3, JsonWriter> writeVector3 = (v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteProperty("z", v.z);
w.WriteObjectEnd();
};
JsonMapper.RegisterExporter<Vector3>((v, w) => { writeVecto
// 注册Vector4类型的Exporter
JsonMapper.RegisterExporter<Vector4>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteProperty("z", v.z);
w.WriteProperty("w", v.w);
w.WriteObjectEnd();
});
// 注册Quaternion类型的Exporter
JsonMapper.RegisterExporter<Quaternion>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteProperty("z", v.z);
w.WriteProperty("w", v.w);
w.WriteObjectEnd();
});
// 注册Color类型的Exporter
JsonMapper.RegisterExporter<Color>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("r", v.r);
w.WriteProperty("g", v.g);
w.WriteProperty("b", v.b);
w.WriteProperty("a", v.a);
w.WriteObjectEnd();
});
// 注册Color32类型的Exporter
JsonMapper.RegisterExporter<Color32>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("r", v.r);
w.WriteProperty("g", v.g);
w.WriteProperty("b", v.b);
w.WriteProperty("a", v.a);
w.WriteObjectEnd();
});
// 注册Bounds类型的Exporter
JsonMapper.RegisterExporter<Bounds>((v, w) =>
{
w.WriteObjectStart();
w.WritePropertyName("center");
writeVector3(v.center, w);
w.WritePropertyName("size");
writeVector3(v.size, w);
w.WriteObjectEnd();
});
// 注册Rect类型的Exporter
JsonMapper.RegisterExporter<Rect>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("x", v.x);
w.WriteProperty("y", v.y);
w.WriteProperty("width", v.width);
w.WriteProperty("height", v.height);
w.WriteObjectEnd();
});
// 注册RectOffset类型的Exporter
JsonMapper.RegisterExporter<RectOffset>((v, w) =>
{
w.WriteObjectStart();
w.WriteProperty("top", v.top);
w.WriteProperty("left", v.left);
w.WriteProperty("bottom", v.bottom);
w.WriteProperty("right", v.right);
w.WriteObjectEnd();
}); }
}
public static class JsonExtensions
{
public static void WriteProperty(this JsonWriter w, string name, long value)
{
w.WritePropertyName(name);
w.Write(value);
}
public static void WriteProperty(this JsonWriter w, string name, string value)
{
w.WritePropertyName(name);
w.Write(value);
}
public static void WriteProperty(this JsonWriter w, string name, bool value)
{
w.WritePropertyName(name);
w.Write(value);
}
public static void WriteProperty(this JsonWriter w, string name, double value)
{
w.WritePropertyName(name);
w.Write(value);
} public static void WriteProperty(this JsonWriter w, string name, float value)
{
w.WritePropertyName(name);
w.Write(value);
}
}

LitJson报错记录的更多相关文章

  1. 报错记录(xml抬头报错)

    报错记录(xml抬头报错) Referenced file contains errors (http://www.springframework.org/schema/beans/spring-be ...

  2. IDEA 报错记录

    IDEA 报错记录 Process finished with exit code 0 这种主要是配了默认的 Tomcat ,然后又配置了外部的 Tomcat.解决办法,注释掉默认的: <dep ...

  3. Spring Boot 报错记录

    Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...

  4. 报错记录:getOutputStream() has already been called for this response

    仅作记录:参考文章:http://www.blogjava.net/vickzhu/archive/2008/11/03/238337.html 报错信息: java.lang.IllegalStat ...

  5. g++ 6.4编译opencv-2.4.10报错记录

      fetch公司的项目进行编译,此项目依赖opencv库.由于本人一直比较偏爱fedora,但也因此给我带来了许多"乐趣"(麻烦).fedora一直走得比较前沿,g++ 6.3了 ...

  6. windows的bpython安装方法以及数据库报错--记录

    ---恢复内容开始--- 安装bpython的时候发现了一个博客讲解如何成功安装bpython,分享一下链接http://www.cnblogs.com/zhaojiedi1992/p/zhaojie ...

  7. RabbitMq 报错记录

    只记录本人当时遇到的情况,仅作参考 添加消息队列报错:The connection cannot support any more channels. Consider creating a new ...

  8. zabbix3.0报错记录

    一.问题描述 在zabbix_server添加变量时,出现了以下的报错,

  9. scrapy shell 中文网站输出报错.记录.

    UnicodeDecodeError: 'gbk' codec can't decode bytes in position 381-382: illegal multibyte sequence 上 ...

随机推荐

  1. 好客租房42-react组件基础综合案例-渲染列表无数据并优化

    渲染列表评论 1判断列表数据的长度是否为0 2如果为0 则渲染暂无评论 //导入react import React from 'react' import ReactDOM from 'react- ...

  2. java通过socket实现https get 请求网页

    1. 首先要初始化ssl context SSLContext context = SSLContext.getDefault(); socket = (SSLSocket) context.getS ...

  3. Bean Validator

    Bean Validator 关于Jakarta EE 2018年03月, Oracle 决定把 JavaEE 移交给开源组织 Eclipse 基金会,并且不再使用Java EE这个名称. 因此jav ...

  4. 写selenium常用到的js代码

    selenium可以运行JavaScript代码,可以用一些JavaScript来辅助编写Selelnium代码. 1.scrollIntoView - 向下拉滚动条,使得某元素可见 IWebElem ...

  5. 李呈祥:bilibili在湖仓一体查询加速上的实践与探索

    导读: 本文主要介绍哔哩哔哩在数据湖与数据仓库一体架构下,探索查询加速以及索引增强的一些实践.主要内容包括: 什么是湖仓一体架构 哔哩哔哩目前的湖仓一体架构 湖仓一体架构下,数据的排序组织优化 湖仓一 ...

  6. 论文解读(GraphMAE)《GraphMAE: Self-Supervised Masked Graph Autoencoders》

    论文信息 论文标题:GraphMAE: Self-Supervised Masked Graph Autoencoders论文作者:Zhenyu Hou, Xiao Liu, Yukuo Cen, Y ...

  7. 引入gitlab仓库代码到npm包的教程

    背景介绍 随着人类地发展,社会地进步,计算机技术地更新迭代,每一片码海里都有它宝贵的财富,每一座码山里都有着各自的秘密.怎么守住财富,隐藏一些秘密,成了一些开发人员所关心的事情. 需求分析 简单地说, ...

  8. tableSizeFor

    HashMap tableSizeFor() /** Returns a power of two size for the given target capacity. 1.(不考虑大于最大容量的情 ...

  9. SAP -熟练使用T-Code SHD0

    SHD0 业务顾问和开发顾问都非常熟悉的一个T-Code, 如果能合理使用它,可以省去许多增强和程序修改工作. 当我需要时,我在这里找不到任何相关文档,这就是为什么我想借此机会向我们自己的SCN提供内 ...

  10. RocketMQ 集群的搭建部署 以及rocketmq-console-ng仪表台的安装部署

    在 RocketMQ 主要的组件如下. NameServerNameServer 集群,Topic 的路由注册中心,为客户端根据 Topic 提供路由服务,从而引导客户端向 Broker 发送消息.N ...