Beispiel #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{
            configInfo      = Resources.Load <TextAsset>(jsonPath);
            keyvalueInfoObj = JsonUtility.FromJson <KeyValuesInfo>(configInfo.text);
        }
        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);
        }
    }
    /// <summary>
    /// 处理Json文件
    /// </summary>
    /// <param name="jsonPath"></param>
    private void InitAndAnalysisJson(string jsonPath)
    {
        TextAsset     configInfo       = null;
        KeyValuesInfo keyValuesInfoObj = null;

        if (string.IsNullOrEmpty(jsonPath))
        {
            return;
        }
        //解析Json
        try
        {
            configInfo       = Resources.Load <TextAsset>(jsonPath);
            keyValuesInfoObj = JsonUtility.FromJson <KeyValuesInfo>(configInfo.text);
        }
        catch
        {
            throw new JsonAnlysisException(GetType() + "Analysis Excepton");
        }
        foreach (KeyValuesNode nodeInfo in keyValuesInfoObj.ConfigInfo)
        {
            _appSetting.Add(nodeInfo.Key, nodeInfo.Value);
        }
    }