位置: 编程技术 - 正文

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)

  • 福建国税网上办税平台登录
  • 企业的罚款支出包括违约金吗
  • 个人所得税计提分录怎么写
  • 个人所得税速算扣除数表
  • 企业之间借款利息进项税可以抵扣吗
  • 合伙企业缓交所得税
  • 不动产租赁属于经营租赁吗
  • 工程招标费计入什么科目
  • 单一环节征税有哪些类型
  • 公司改名之前发工资吗
  • 计提社保贷方科目是什么
  • 未开具发票负数的原因
  • 商业零售企业实行增值税后购进商品业务的账务处理
  • 其他货币资金是资产类科目吗
  • 转账显示未认证
  • 查补以前年度所得税如何填写申报表
  • 开发商买商铺
  • 不交社保的单位违法吗?
  • 发工资时计提个人所得税
  • 变更税务登记证法人需要哪些资料
  • 机票退票费能抵扣旅客进项税吗
  • 残疾人保障金中的工资总额包括福利费用吗
  • 可供出售金融资产是指什么
  • 哪些研发费用可以资本化
  • 利润表有盈利能力吗
  • 研发支出的二级科目是什么
  • 年终股东利润分配方案
  • 个人取得的工资、薪金所得应按次征收个人所得税
  • 民间非营利组织会计制度会计科目
  • 销售部门品种多怎么说
  • 先入费用后来发票怎么做账
  • 招待客户住宿费用计入什么科目
  • 使用php进行mysql数据库编程的基本步骤
  • 贷款损失准备科目为负债类科目
  • Uniapp使用$base方法
  • php echo语句
  • php 写入excel
  • 计算机视觉需要学什么
  • 损失函数是什么
  • 简单html代码
  • 没有关系怎么表达
  • GCN经典论文笔记:Semi-Supervised Classification with Graph Convolutional Networks
  • phpcms使用教程
  • 企业销售旧车增值税处理
  • 企业所得税营业收入怎么填
  • 税率与征收率是怎么回事
  • 暂存的凭证是怎么做的
  • SQL Sever2008r2 数据库服务各种无法启动问题的解决办法(详解)
  • 营业外支出的会计要素
  • 利润表中的利息费用是利息支出吗
  • 固定资产一次性计入费用的账务处理
  • 多交个税收到退回怎么办
  • 去年的成本做少了咋办
  • 股权拍卖溢价部分怎么算
  • 公司购买的财产保险要交印花税吗
  • SQL Server提示"选定的用户拥有对象,所以无法除去该用户”
  • 如何删除windows media center
  • XP系统连接VPN提示错误633:调制解调器已在使用的解决方法图文教程
  • 播放winner
  • centos6.5mini安装教程
  • windows10 rs2
  • windows102021年更新
  • ubuntu20.04软件中心
  • linux中安装软件可使用哪些方式
  • 如何返回系统
  • win8硬盘占用100%
  • win7系统在那个文件夹
  • cent linux
  • win7系统打不开设备与打印机
  • 事件处理的三个要素
  • jquery prompt
  • bootstrap4和3
  • nodejs的require
  • js分段上传
  • 解读JavaScript中 For, While与递归的用法
  • python字符串拼接join
  • 电子税务局打印发票提示本机未检测到
  • 宁夏退休职工网上认证
  • 个人所得税票样
  • 沙宣发型适合什么年龄女性
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设