位置: 编程技术 - 正文

jasonToObject

编辑:rootadmin
/// <summary> /// 获得表单全路径 /// </summary> static string TextPath(string filename) { string txtPath = string.Empty;#if UNITY_IPHONEtxtPath = Application.dataPath &#; "/Raw/Text/" &#; filename &#; ".json";#else txtPath = Application.dataPath &#; "/../Documents/Text/" &#; filename &#; ".json";#endif //Debug.Log("加载配置文件:" &#; txtPath); return txtPath; } #region 读取配置文件 static string ReadFile(string fileName) {#if UNITY_ANDROID TextAsset txtAsset = Resources.Load("Text/" &#; fileName, typeof(TextAsset)) as TextAsset; string content = txtAsset.text;#else string content = string.Empty; using (StreamReader sr = new StreamReader(TextPath(fileName))) { content = sr.ReadToEnd(); sr.Close(); sr.Dispose(); }#endif return content; } static void LoadDevelopExpInfo() { ConfigurationTables.Instance.DevelopExpDatas.Clear(); List<object> pveList = Json.Deserialize(ReadFile(devexp)) as List<object>; for (int i = 0; i < pveList.Count; i&#;&#;) { Dictionary<string, object> dic = pveList[i] as Dictionary<string, object>; using (DevelopExp info = DeSerialize<DevelopExp>(typeof(DevelopExp), dic) as DevelopExp) { ConfigurationTables.Instance.DevelopExpDatas.Add(info); } } } static object DeSerialize<T>(Type type, Dictionary<string, object> dic) where T : new() { FieldInfo[] fInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty); object obj = System.Activator.CreateInstance(type); List<object> result; for (int i = 0; i < fInfos.Length; i&#;&#;) { if (dic.ContainsKey(fInfos[i].Name)) { switch (fInfos[i].FieldType.ToString()) { case "System.String": fInfos[i].SetValue(obj, dic[fInfos[i].Name].ToString()); break; case "System.Int": fInfos[i].SetValue(obj, int.Parse(dic[fInfos[i].Name].ToString())); break; case "System.Single": fInfos[i].SetValue(obj, float.Parse(dic[fInfos[i].Name].ToString())); break; case "System.Collections.Generic.List`1[System.Int]": result = dic[fInfos[i].Name] as List<object>; List<int> list = new List<int>(); for (int j = 0; j < result.Count; j&#;&#; ) { list.Add(int.Parse(result[j].ToString())); } fInfos[i].SetValue(obj, list); break; case "System.Int[]": result = dic[fInfos[i].Name] as List<object>; int[] val = new int[result.Count]; for (int j = 0; j < result.Count; j&#;&#;) { val[j] = int.Parse(result[j].ToString()); } fInfos[i].SetValue(obj, val); break; case "System.String[]": result = dic[fInfos[i].Name] as List<object>; string[] str = new string[result.Count]; for (int j = 0; j < result.Count; j&#;&#;) { str[j] = result[j].ToString(); } fInfos[i].SetValue(obj, str); break; } } } return obj; }} /// <summary> /// 获得表单全路径 /// </summary> static string TextPath(string filename) { string txtPath = string.Empty;#if UNITY_IPHONEtxtPath = Application.dataPath &#; "/Raw/Text/" &#; filename &#; ".json";#else txtPath = Application.dataPath &#; "/../Documents/Text/" &#; filename &#; ".json";#endif //Debug.Log("加载配置文件:" &#; txtPath); return txtPath; } #region 读取配置文件 static string ReadFile(string fileName) {#if UNITY_ANDROID TextAsset txtAsset = Resources.Load("Text/" &#; fileName, typeof(TextAsset)) as TextAsset; string content = txtAsset.text;#else string content = string.Empty; using (StreamReader sr = new StreamReader(TextPath(fileName))) { content = sr.ReadToEnd(); sr.Close(); sr.Dispose(); }#endif return content; } static void LoadDevelopExpInfo() { ConfigurationTables.Instance.DevelopExpDatas.Clear(); List<object> pveList = Json.Deserialize(ReadFile(devexp)) as List<object>; for (int i = 0; i < pveList.Count; i&#;&#;) { Dictionary<string, object> dic = pveList[i] as Dictionary<string, object>; using (DevelopExp info = DeSerialize<DevelopExp>(typeof(DevelopExp), dic) as DevelopExp) { ConfigurationTables.Instance.DevelopExpDatas.Add(info); } } } static object DeSerialize<T>(Type type, Dictionary<string, object> dic) where T : new() { FieldInfo[] fInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty); object obj = System.Activator.CreateInstance(type); List<object> result; for (int i = 0; i < fInfos.Length; i&#;&#;) { if (dic.ContainsKey(fInfos[i].Name)) { switch (fInfos[i].FieldType.ToString()) { case "System.String": fInfos[i].SetValue(obj, dic[fInfos[i].Name].ToString()); break; case "System.Int": fInfos[i].SetValue(obj, int.Parse(dic[fInfos[i].Name].ToString())); break; case "System.Single": fInfos[i].SetValue(obj, float.Parse(dic[fInfos[i].Name].ToString())); break; case "System.Collections.Generic.List`1[System.Int]": result = dic[fInfos[i].Name] as List<object>; List<int> list = new List<int>(); for (int j = 0; j < result.Count; j&#;&#; ) { list.Add(int.Parse(result[j].ToString())); } fInfos[i].SetValue(obj, list); break; case "System.Int[]": result = dic[fInfos[i].Name] as List<object>; int[] val = new int[result.Count]; for (int j = 0; j < result.Count; j&#;&#;) { val[j] = int.Parse(result[j].ToString()); } fInfos[i].SetValue(obj, val); break; case "System.String[]": result = dic[fInfos[i].Name] as List<object>; string[] str = new string[result.Count]; for (int j = 0; j < result.Count; j&#;&#;) { str[j] = result[j].ToString(); } fInfos[i].SetValue(obj, str); break; } } } return obj; }}

推荐整理分享jasonToObject,希望有所帮助,仅作参考,欢迎阅读内容。

jasonToObject

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

loading问题 通常游戏的主场景包含的资源较多,这会导致加载场景的时间较长。为了避免这个问题,可以首先加载Loading场景,然后再通过Loading场景来加载主场景。

缩放 缩放分类:unity--:人阅读评论(0)收藏举报unityusingUnityEngine;usingSystem.Collections;publicclassMove:MonoBehaviour{#ifUNITY_IPHONE||UNITY_ANDROID||UNITY_WP8||UNITY_BLACKBER

AI控制器 usingUnityEngine;usingSystem.Collections;publicclassEnemyController:MonoBehaviour{///summary///血条类////summary[HideInInspector]publicPlayerHealthhealth;///summary///移动的方向////summary[Hid

标签: jasonToObject

本文链接地址:https://www.jiuchutong.com/biancheng/369381.html 转载请保留说明!

上一篇:相机渲染(相机渲染图片)

下一篇:loading问题(loading and loading)

  • 注销空白缴销发票流程
  • 跨年租赁费如何处理
  • 公司购买食品如何入账
  • 外聘人员需要申报个税吗
  • 领用包装物的会计分录
  • 报关单位的信用管理制度
  • 递延收益负债类科目
  • 什么情况下可要求厂商出品质保证书
  • 一般借款资本化加权平均数
  • 资产损失税前扣除是什么意思
  • 购买的风机如何做分录
  • 固定资产折旧属于制造费用吗
  • 小微企业季度超过45万如何填申报表
  • 外地预缴个人所得税会计分录
  • 车间扫帚存放架子
  • 核定征收取消了
  • 库存现金盘点发现现金多怎么处理
  • 未开票的增值税发票能验旧吗
  • 发票先入账,但发票不对
  • 应收账款零头没有收到如何账务处理
  • 电脑不支持windows 11
  • swstrtr.exe - swstrtr是什么进程
  • 个人以房产投资一人有限公司时,房产要开发票吗
  • arm on windows
  • 上一年度的费用入账需要分摊吗
  • PHP:Memcached::getStats()的用法_Memcached类
  • linux漏洞复现
  • 超额累进税率包括
  • 编写守护进程
  • 辅导期内的企业有哪些
  • 电脑桌面调出键盘
  • php实现微信发红包的方法
  • 销售固定资产利润率
  • 混合成本的分解方法很多,通常有
  • 报错500是什么意思
  • 国家规定免税饲料具体哪些产品
  • 应收票据其他应收款都需要提取坏账准备么
  • 劳务报酬可以扣除合理支出吗
  • 基于Python实现五大常用分类算法(原理+代码)
  • 宝塔面板使用教程
  • 大前端技术
  • 公司地面硬化财务如何入账
  • access2010宏操作大全
  • 收到的销项负数发票如何申报
  • 租赁收入会计分录怎么做
  • 建筑设备的概念,作用及其研究内容
  • 个人劳务费免税额度 年度
  • sqlserver2005使用教程
  • mysql怎么给字段添加中文备注
  • 疫情期间餐饮发票税点
  • 收到承兑汇票在什么科目
  • 现金抵用券使用说明怎么写
  • 外借资质交企业所得税怎么交
  • 当月作废的采购发票已认证账务如何处理?
  • 年底结账会计要怎么做账
  • 公司车折旧会计分录
  • 个人账号可以向对公账户转账吗
  • 原材料暂估的账务处理
  • centosyum源
  • 屏幕右下角显示A2
  • win7无法识别usb设备如何解决
  • win10小娜语音激活
  • 启用5g后流量有什么影响
  • macfic
  • win7偶尔黑屏
  • 系统运行缓慢解决方法
  • linux生成文件
  • 新买的笔记本电脑需要做什么
  • listview安卓
  • 导入项目出现这个问题
  • 狗刨好学吗
  • javascript延迟执行
  • 脚本添加crontab
  • 木瓜电子
  • ugui粒子ui层级
  • django批量上传图片
  • python中的get方法
  • 山西省税务局投诉平台
  • 北京国税办税服务厅
  • 实收资本印花税税率多少
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设