位置: 编程技术 - 正文

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)

  • 怎样在网上申报营业执照年检
  • 注册会计师考试时间2023
  • 二手车交易税是谁交
  • 企业合并怎么处理
  • 房屋租赁的发票备注怎么写
  • 已经缴税的发票还能作废吗
  • 环保税申报表怎么填制
  • 小规模纳税人免税怎么做账
  • 购买生产设备上税怎么算
  • 抵扣白条账单是怎么回事
  • 租入固定资产改扩建
  • 计提上一年度企业所得税会计分录
  • 房租不能开发票怎样入账
  • 特定资产收益权融资业务
  • 税收优惠退回的税金怎么入账
  • 企业发生的借款费用,可直接归属于
  • 增值税普通发票和专用发票有什么区别
  • 北京建筑施工企业排名
  • 本年累计应交税费需要加上年初数吗
  • 应交增值税出口退税科目怎么结平
  • 股份利润怎么分
  • 供热公司向用户提供
  • 收到小额支付转账什么意思
  • 企业所得税季度申报表A类
  • 购买办公用品发放给各部门使用
  • php5.4+mysql
  • windows10什么时候上市
  • php中变量有哪些基本数据类型?
  • php字符串函数有哪些
  • 工程暂估收入入账的会计分录
  • php 字符串函数
  • PHP:Memcached::__construct()的用法_Memcached类
  • 最轻便的蓝光刻录机品牌
  • 有关增值税的计算真题
  • 弃置费用预计负债递延所得税怎么处理
  • 科纳克里市
  • html调查问卷简单代码
  • mysql如何避免锁表
  • gym版本和render函数
  • go语言入门指南
  • 商业积分消费模式
  • 单位有残疾人能享受
  • 代垫费用开票明细怎么写
  • Python变量中forain
  • vj刷题
  • 小微企业应纳税所得额计算
  • 加计扣除所得税处理
  • 工资单应该盖什么章
  • 先付款后开票怎样写证明
  • 收到对方公司的货款怎么记账
  • 房地产企业代收费用
  • 不动产进项税额抵扣从什么时候开始
  • 营利性养老机构有补贴吗
  • 利润分配的账务处理实验报告
  • 实缴增值税比计提增值税少怎么做账务处理
  • 税种的分类方法有哪些
  • 筹建期的开办费开业后如何处理
  • 劳务公司 成本
  • 申请开立基本存款账户时,银行应按照
  • 企业发生的经济业务主要有哪些
  • 分公司给总公司分红怎么入账
  • 收入成本的确认条件
  • 房租费计提如何入账
  • 刻章发票可以抵扣吗
  • mysql sql行转列
  • mysql 5.6.23 winx64.zip安装详细教程
  • 下载windows vista
  • 怎么添加第二个人脸识别
  • NDSTray.exe - NDSTray是什么进程 有什么用
  • linux ssh 登录
  • nodejs做接口
  • 批处理语言 从入门到精通
  • 经过整理的一些成语
  • unity错误cs1002
  • linux怎么使用c语言
  • pcs可以使用什么在任何地方以各种速率与网络保持联络
  • jquery 操作json
  • De facto standard 世界上不可思议的事实标准
  • 个体工商户个人所得税
  • 湖北耕地占用税标准
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设