位置: 编程技术 - 正文

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)

  • 税务清算需要什么条件
  • 累计折旧 计提折旧
  • 对公付款对方不开发票怎么处理
  • 去参加博览会的英文
  • 开了票印花税必须报吗
  • 承兑汇票区别
  • 行政事业单位预算管理制度
  • 通用机打发票还能用吗
  • 为什么社保账户有钱但是卡里没钱
  • 老板从公司拿钱怎么拿税最低
  • 支付个人无发票怎么入账
  • 不征税收入怎么申报企业所得税
  • 科研项目间接费用会计分录
  • 社保扣除当月工资还是上个月
  • 子公司给母公司开票
  • 客户把发票弄丢了,红冲重新开了会有什么风险
  • 增值税开票税额交税差额怎么入账
  • 一般纳税人要交的税种有几种
  • 办公室租金相关法规
  • 7年利率多少
  • 印花税无法申报怎么回事
  • 此次新政策对原来就是小型微利企业的纳税人有影响吗?
  • 场地维修属于什么费用
  • 商品进销差价主营业务收入
  • mac big sur 新功能
  • 车船税怎么计账
  • php数据结构
  • 电脑avc是什么意思
  • 营业外收支的内容
  • 预加载的目的是什么
  • php include和include_once
  • 怎么查商品的税率
  • 新政府会计制度科目解读
  • 不构成业务的反义词
  • js实现继承属性功能
  • php 截取字符
  • ubuntu卸载ubuntu-desktop
  • 净利润弥补以前年度亏损
  • 固定资产盘亏是管理费用吗
  • 其他支出怎么做账
  • 年末计提哪些科目
  • 维修费用的处理规定
  • db2入门
  • 深入浅出embedding pdf
  • 一次性扣除固定资产出售处理
  • 毛利率代表什么?如何计算毛利率?
  • 增值税专用发票电子版
  • 调整凭证能不能做2个贷方
  • 补发工资如何计算个税
  • 实物返利的税务处理
  • 河道工程修建维护管理费何时开始停征?
  • 不同银行的存款
  • 企业职工薪酬如何确定
  • 政府补助的内容
  • 会计利润和税务利润的差异是什么
  • 企业偿债能力的含义
  • mysql的操作方法
  • mysql 5.7.11 winx64.zip安装配置方法图文教程
  • win8旗舰版和专业版区别
  • wind10手机
  • exe什么意思?
  • git 进阶
  • linux apache2配置
  • win10系统注册名修改
  • 使用jquery实现的项目
  • ligerUI---ListBox(列表框可移动的实例)
  • 断开网络联结的手机
  • 控制程序的先后顺序是怎样的
  • jquery示例
  • xp启动项 命令
  • android contextmenu
  • unity3d如何发布ios教程
  • android基础入门教程
  • python编程快速
  • 浅析jQuery Ajax通用js封装
  • ActivityManagerService (三)
  • UIAutomator在AndroidStudio中的使用
  • 长春税务局待遇如何
  • 进货没有发票怎么报税
  • 外籍人个人所得税汇算清缴流程
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设