/// <summary>
///写入文件
/// </summary>
/// <param name="Stns"></param>
/// <returns></returns>
public ActionResult WriteJsonFile(string Stns)
{
string filepath = Server.MapPath("~/Content/json/setcamera.json");
string[] stnList = Stns.Split(',');
string output = Newtonsoft.Json.JsonConvert.SerializeObject(stnList, Newtonsoft.Json.Formatting.Indented);
System.IO.File.WriteAllText(filepath, output);
return Json(new { code = 200, message = "保存成功" });
}
/// <summary>
///读取文件
/// </summary>
/// <param name="Stns"></param>
/// <returns></returns>
public ActionResult ReadJsonFile()
{
string filepath = Server.MapPath("~/Content/json/setcamera.json");
string json = string.Empty;
using (FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
{
json = sr.ReadToEnd().ToString();
}
}
string[] stnList = JsonConvert.DeserializeObject<string[]>(json);
return Json(stnList);
}