/// <summary> /// Deserializes the data. /// </summary> /// <returns> /// The data. /// </returns> /// <param name='jsonObj'> /// If set to <c>true</c> json object. /// </param> public virtual bool DeserializeData(IDictionary <string, object> jsonObj) { Logger.Log("[LocalStorage] DeserializeData - " + jsonObj.Count); int intValue = 0; float floatValue = 0; double doubleValue = 0; foreach (var kv in jsonObj) { //if(false == Array.Exists(LocalStorageKeys.MIGRATION_KEYS_TO_IGNORE, k => k == kv.Key)) { string value = kv.Value.ToString(); if (int.TryParse(value, out intValue)) { SetInt(kv.Key, intValue); } else if (float.TryParse(value, out floatValue)) { SetFloat(kv.Key, floatValue); } else if (double.TryParse(value, out doubleValue)) { SetFloat(kv.Key, (float)doubleValue); } else { SetString(kv.Key, value); } //} } Logger.Log("[LocalStorage] DeserializeData Complete"); return(true); }
/// <summary> /// Reads the data from file. /// </summary> protected virtual void ReadDataFromFile() { string data = null; try { if (File.Exists(FILE_PATH)) { Logger.Log("[JSONLocalStorage] Opening: " + FILE_PATH); using (StreamReader sr = new StreamReader(FILE_PATH)) { data = sr.ReadToEnd(); } } } catch (Exception ex) { Logger.LogError("[JSONLocalStorage] Error in ReadDataFromFile - " + ex.Message); } Deserialize(data); }