public static string ReadFileFromPath(string path, EncodingType type = EncodingType.UTF8) { string line = ""; return(DelegateUtil.TryExecute(() => { if (File.Exists(path)) { StreamReader sr = new StreamReader(path, BytesExt.GetEncoding(type)); while ((line = sr.ReadLine()) != null) { line = sr.ReadToEnd(); return line; } } return line; }, line)); }
public static IDictionary <string, string> GetKeyValuesFromPath(string path, EncodingType type = EncodingType.UTF8) { try { CheckNull.ArgumentIsNullException(path, nameof(path)); using (StreamReader streamReader = new StreamReader(path, BytesExt.GetEncoding(type))) { _data.Clear(); _reader = new JsonTextReader(streamReader) { DateParseHandling = 0 }; JObject jObject = JObject.Load(_reader); new JsonDict().VisitJObject(jObject); return(_data); } } catch (Exception) { throw new FormatException("json格式不正确"); } }