位置: 编程技术 - 正文

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)

  • 个体工商户核定征收
  • 长期零申报的公司容易注销吗
  • 小规模纳税人销售农产品税率是多少
  • 提前一个月完工奖励10万元
  • 中山哪家企业招聘残疾人
  • 购进灭火器材怎么入账
  • 应付职工薪酬为什么不属于金融负债
  • 预借差旅费附什么原始凭证
  • 过路费是来回收费还是单向
  • 事业单位银行存款余额组成
  • 企业注销的时候未分配利润怎么处理
  • 政府扶贫支出
  • 去税务局核定税种怎么填
  • 营改增后还有消费税吗
  • 建筑分包项目有哪些内容
  • 第二个季度
  • 长期待摊费用无发票怎么处理
  • 既销售货物又提供劳务例题
  • 物业公司收的预存水费不够抵减怎么交税
  • 给客户的回扣做账时怎么写情况说明
  • 冲失业保险分录怎么做
  • 已预缴的城建税会计分录
  • 如何正确使用储存卡
  • 巴蒂斯塔卡里
  • php中实现文件的上传需要使用哪个全局变量
  • 加班餐费税前扣除问题
  • 销售购物卡如何交税
  • 以太网默认网关怎么查看
  • 其他应付款余额在借方表示什么意思
  • 结算应付职工薪酬怎么算
  • php写文件函数
  • 会计准则 职工福利
  • querywrapper多表联查
  • php的time函数
  • 公司的一项专利多少钱
  • 财政拨款结余明细科目编码
  • 计提工会经费是什么工资项目
  • SQL Server 2016 CTP2.2安装配置方法图文教程
  • mysql数据数据库
  • 代扣代缴消费税怎么算
  • 为什么盈利要利息呢
  • sql server触发器在哪里?
  • 合同结算属于资产吗
  • 国际结算手续费收入增值税
  • 生产自己的产品
  • 一般纳税人改成小规模可以吗
  • 海关报关单海关签章
  • 购车税费怎样计算2023
  • 发票服务内容写错怎么办
  • 公益性捐赠支出计入什么科目
  • 买卖股票手续费怎么算
  • 承包工程合同书
  • 系统多交税款放在哪里
  • 企业无形资产入账标准
  • mysql 5.7.28安装
  • centos6yum源
  • acs_log是什么文件
  • 在linux系统中安装软件
  • xp系统怎么安装网络驱动
  • linux或者命令
  • 复制打开网页
  • 2016年首个国家安全教育日
  • windows7怎么设置右键菜单
  • python批量更改文件名称
  • ext.formpanel
  • android注册界面设计
  • python如何判断一个变量的类型
  • celery使用
  • nodejs增删改查
  • nodejs中的session
  • android 笔记软件推荐
  • 怎样设置安卓等比例显示按钮
  • unity获取手机型号
  • ugui粒子ui层级
  • javascript tab切换
  • checkbox选中一个其余选项置灰
  • jquery设置图片大小
  • 个体户增值税怎么计算方法
  • 写给税务局的表扬信
  • 土地交的契税会计科目
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设