LitJson扩展支持float类型和自定义类型
LitJson 下载地址 跳转
参考:魔改LitJson
LitJson 支持的格式如下:
public JsonData(bool boolean);
public JsonData(double number);
public JsonData(int number);
public JsonData(long number);
public JsonData(object obj)
public JsonData(string str);
不支持解析 float Vector3 Vector2 Quaternion 以及自定义类型
但是LItJson 提供扩展接口 实现如下:
在使用 解析前 调用LitJsonRegiter.Register() 就行
using LitJson;
using Lockstep.Math;
using System;
using UnityEngine;public class LitJsonRegiter
{public static void Register(){RegiterType();RegisterFloat();RegisterLFloat();RegisterLVertor3();RegisterLVertor2();RegisterVector3();RegisterVector2();RegisterQuaternion();RegisterGameObject();}public static void RegiterType(){void Exporter(Type obj, JsonWriter writer){writer.Write(obj.FullName);}JsonMapper.RegisterExporter((ExporterFunc<Type>)Exporter);Type Importer(string obj){return Type.GetType(obj);}JsonMapper.RegisterImporter((ImporterFunc<string, Type>)Importer);}private static void RegisterFloat(){void Exporter(float obj, JsonWriter writer){writer.Write(obj);}JsonMapper.RegisterExporter((ExporterFunc<float>)Exporter);float Importer(double obj){return (float)obj;}JsonMapper.RegisterImporter((ImporterFunc<double, float>)Importer);}private static void RegisterLFloat(){void Exporter(LFloat obj, JsonWriter writer){writer.Write(obj.ToLong().ToString());}JsonMapper.RegisterExporter((ExporterFunc<LFloat>)Exporter);LFloat Importer(string obj){return new LFloat(long.Parse(obj)); }JsonMapper.RegisterImporter((ImporterFunc<string, LFloat>)Importer);}private static void RegisterLVertor2(){void Exporter(LVector2 obj, JsonWriter writer){writer.WriteObjectStart();writer.WritePropertyName("x");//写入属性名writer.Write(obj.x);//写入值writer.WritePropertyName("y");writer.Write(obj.y);writer.WriteObjectEnd();}JsonMapper.RegisterExporter((ExporterFunc<LVector2>)Exporter);//序列化}private static void RegisterLVertor3(){void Exporter(LVector3 obj, JsonWriter writer){writer.WriteObjectStart();writer.WritePropertyName("x");//写入属性名writer.Write(obj.x);//写入值writer.WritePropertyName("y");writer.Write(obj.y);writer.WritePropertyName("z");writer.Write(obj.z);writer.WriteObjectEnd();}JsonMapper.RegisterExporter((ExporterFunc<LVector3>)Exporter);//序列化}private static void RegisterVector3(){void Exporter(Vector3 obj, JsonWriter writer){writer.WriteObjectStart();writer.WritePropertyName("x");//写入属性名writer.Write(obj.x);//写入值writer.WritePropertyName("y");writer.Write(obj.y);writer.WritePropertyName("z");writer.Write(obj.z);writer.WriteObjectEnd();}JsonMapper.RegisterExporter((ExporterFunc<Vector3>)Exporter);//序列化}private static void RegisterVector2(){void Exporter(Vector2 obj, JsonWriter writer){writer.WriteObjectStart();writer.WritePropertyName("x");//写入属性名writer.Write(obj.x);//写入值writer.WritePropertyName("y");writer.Write(obj.y);writer.WriteObjectEnd();}JsonMapper.RegisterExporter((ExporterFunc<Vector2>)Exporter);//序列化}private static void RegisterQuaternion(){void Exporter(Quaternion obj, JsonWriter writer){writer.WriteObjectStart();writer.WritePropertyName("x");//写入属性名writer.Write(obj.x);//写入值writer.WritePropertyName("y");writer.Write(obj.y);writer.WritePropertyName("z");writer.Write(obj.z);writer.WritePropertyName("w");writer.Write(obj.w);writer.WriteObjectEnd();}JsonMapper.RegisterExporter((ExporterFunc<Quaternion>)Exporter);//序列化}private static void RegisterGameObject(){void Exporter(GameObject obj, JsonWriter writer){writer.WriteObjectStart();writer.WritePropertyName("name");//写入属性名if (obj != null)writer.Write(obj.name);//写入值elsewriter.Write("Prefab为Null");//写入值writer.WriteObjectEnd();}JsonMapper.RegisterExporter((ExporterFunc<GameObject>)Exporter);//序列化}
}
LitJson扩展支持float类型和自定义类型相关推荐
- oracle自定义的记录类型,oracle 自定义类型 type / create type
一:Oracle中的类型有很多种,主要可以分为以下几类: 1.字符串类型.如:char.nchar.varchar2.nvarchar2. 2.数值类型.如:int.number(p,s).integ ...
- 黑马程序员C语言基础(第八天)复合类型(自定义类型)(结构体)、共用体(联合体)、枚举enum、 typedef
黑马程序员C语言基础(第一天) 黑马程序员C语言基础(第二天) 黑马程序员C语言基础(第三天) 黑马程序员C语言基础(第四天)数据类型 黑马程序员C语言基础(第五天)运算符与表达式.程序流程结构.数组 ...
- Groovy中转换成java,Groovy将字符串类型转换为自定义类型的方法
将一个字符串转换为自定义类型: 例如Quantity是自定义的一个class,现在想这么调用 Quantity quantity = "100个" as Quantity 或 de ...
- oracle如何自定义类型,Oracle 自定义类型
一.子类型 这种类型最简单,类似类型的一个别名,主要是为了对常用的一些类型简单化,它基于原始的某个类型.如: 有些应用会经常用到一些货币类型:number(16,2).如果在全局范围各自定义这种类型, ...
- VSCode注册关联自定义类型文件
打开你要注册的文件类型文件[本文中用 ".txt"到".lua"演示] 在VSCode窗口右下角有当前文件类型"Plain Text" 是可 ...
- aidl使用_Android进阶之AIDL如何使用自定义类型
如何在 AIDL 中使用自定义类型,具体步骤如下: 创建自定义类型 声明自定义类型 定义与自定义类型相关的业务 重写业务实体类 远程调用 验证 AIDL 1. 创建自定义类型 自定义类型传输的就是一个 ...
- 【C语言】自定义类型
前言 我们已经学习了编译器自带的类型:int . char .long .float .double- .除了这些类型,编译器还允许我们自己设计类型. 自定义类型包括:结构体 . 枚举 和 联合. 一 ...
- Oracle 自定义类型TYPE(subtype, type object, type body, type table) 用法
原 ORACLE 自定义类型 type/ object 2017年03月28日 13:58:23 tan1012194073 阅读数:5999 版权声明:本文为博主原创文章,未经博主允许不得转载. h ...
- 【Spring5.x】对象的生命周期、配置文件参数化、自定义类型转换器、后置处理Bean
工厂高级特性 对象的生命周期 创建阶段 初始化阶段 - InitializingBean.init-method 销毁阶段 - DisposableBean.destroy-method 对象的生命周 ...
- 自定义类型:结构体、位段、枚举、联合 ------- C语言
C语言中,7可以存放再整型变量中,'c' 可以存放在字符型变量中,3.14可以存放在浮点型变量中,一个学生有:姓名.年龄.性别.学号等.C语言中是否有这样一个可以存放学生的类型呢?答案是肯定的,这一种 ...
最新文章
- Android编程获取网络连接状态及调用网络配置界面
- 开发常见错误解决(3)VS2005调试程序出错,绑定句柄无效 Terminal Services
- 将web项目deploy到tomcat的方法
- Redis 主从复制(replication)
- SLAM数据集(1)
- Android OpenGLES2.0(十六)——3D模型贴图及光照处理(obj+mtl)
- platform_driver_register()--如何match之后调用probe
- python发送文件_Python大文件传输
- shell中变量的引用(两种方式:$变量名,${变量名})。
- ExcelReport第二篇:ExcelReport源码解析
- ps去水印教程_叫板 PS!去水印、抠图、加滤镜,这款超强修图应用到底什么来头...
- C语言图书信息管理系统
- EPLAN 2.7 WIN 10 X64安装说明
- 双三次插值c语言源代码,双三次插值原理及MATLAB源码实现
- vue引入svg图片
- 企业微信公众号怎么建立和运营?
- 将你的现实生活照片变成卡通头像
- html5 运动轨迹绘画,冷知识|简单几步教你用跑步轨迹绘画,用跑画刷爆你的朋友圈!...
- fairyGUI的学习记录1
- 如何生成数据库设计文档
热门文章
- insert触发器实例
- 快播(QvodPlayer)最新版 v5.20.234 官方版
- 咋做数据分析,张口就来RFM模型,结果用错了
- dnf脚本色块补丁_DNF:史上最难地图,没有小怪只有BOSS,做成团本连飞行员都得坠机...
- 曲折中前行的汉语编程
- [RK3288][Android6.0] 调试笔记 --- 播放搜狐视频会Crash问题
- 全国身份证号码归属地表格
- 论Web App、Hybrid App、Native App三类主流APP设计差异
- 番茄花园GHOST SP3无法安装IIS 信息服务的解决方法
- uploadify上传插件完整Demo(包括后台)