Json文件读取

mac2022-06-30  36

public ActionResult About() { #region 读取json文件 // string s = "AbC"; //if(s.Length==0){ // return Content("判断字符串为空的高效写法"); // } var json_str = GetFileJson(Server.MapPath("/Content/Json/info.json")); JArray content = JsonConvert.DeserializeObject<JArray>(json_str); #endregion return View(content); }

public string GetFileJson(string filepath) { string json = string.Empty; using (FileStream fs = new FileStream(filepath, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite)) { //"en-us", "zh-cn", "ar-iq", "de-de" // Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-cn"); using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding(936))) { json = sr.ReadToEnd().ToString(); } } return json; }

转载于:https://www.cnblogs.com/su-su-0107/p/7998110.html

相关资源:读写json文件
最新回复(0)