Ejemplo n.º 1
0
        /// <summary>
        /// 初始化解析Json 数据,加载到集合众。
        /// </summary>
        /// <param name="jsonPath"></param>
        private void InitAndAnalysisJson(string jsonPath)
        {
            TextAsset     configInfo      = null;
            KeyValuesInfo keyvalueInfoObj = null;

            //参数检查
            if (string.IsNullOrEmpty(jsonPath))
            {
                return;
            }
            //解析Json 配置文件
            try
            {
                jsonPath        = Path.Combine("Configs", jsonPath);
                configInfo      = Resources.Load <TextAsset>(jsonPath);
                keyvalueInfoObj = JsonUtility.FromJson <KeyValuesInfo>(configInfo.text);
            }
            catch
            {
                throw new JsonAnlysisException(GetType() + "Json Analysis Exception, Parameter jsonPath =" + jsonPath);
            }

            //数据加载到AppSetting 集合中
            foreach (var nodeInfo in keyvalueInfoObj.ConfigInfo)
            {
                _AppSetting.Add(nodeInfo.Key, nodeInfo.Value);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化解析XML数据,到集合中(_AppSetting)
        /// </summary>
        /// <param name="JsonPath">Json的路径</param>
        private void InitAndAnalysisJson(string JsonPath)
        {
            TextAsset     configInfo       = null;
            KeyValuesInfo keyValuesInfoObj = null;

            //参数检查
            if (string.IsNullOrEmpty(JsonPath))
            {
                return;
            }

            try
            {
                configInfo       = Resources.Load <TextAsset>(JsonPath);
                keyValuesInfoObj = JsonUtility.FromJson <KeyValuesInfo>(configInfo.text);
            }
            catch
            {
                throw new JsonAnalysisException(GetType() + "/InitAndAnalysisJson()/Json Analysis Exception! ,please Check Json file Or Json file Path! Parameter JsonPath= " + JsonPath);
            }
            foreach (KeyValuesNode node in keyValuesInfoObj.ConfigInfo)
            {
                _AppSetting.Add(node.Key, node.Value);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 初始化解析Json 数据,加载到集合众。
        /// </summary>
        /// <param name="jsonPath"></param>
        private void InitAndAnalysisJson(string jsonPath)
        {
            //TextAsset configInfo = null;
            string        strReadContent  = string.Empty;
            KeyValuesInfo keyvalueInfoObj = null;

            //参数检查
            if (string.IsNullOrEmpty(jsonPath))
            {
                return;
            }
            //解析Json 配置文件
            try{
                //configInfo = Resources.Load<TextAsset>(jsonPath);//Original
                //keyvalueInfoObj=JsonUtility.FromJson<KeyValuesInfo>(configInfo.text);//Original

                /*  由Resources 目录改为StreamAsset 目录,造成以下重构代码  */
                strReadContent  = System.IO.File.ReadAllText(jsonPath);
                keyvalueInfoObj = JsonUtility.FromJson <KeyValuesInfo>(strReadContent);
            }
            catch {
                throw new JsonAnlysisException(GetType() + "/InitAndAnalysisJson()/Json Analysis Exception ! Parameter jsonPath=" + jsonPath);
            }
            //数据加载到AppSetting 集合中
            foreach (KeyValuesNode nodeInfo in keyvalueInfoObj.ConfigInfo)
            {
                _AppSetting.Add(nodeInfo.Key, nodeInfo.Value);
            }
        }