数据放到json文档中

public void saveJson(string sbJson)
{
string strPath = HttpContext.Current.Server.MapPath("~/Map");
if (!Directory.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
string jsonwj = DateTime.Now.ToString().Replace(":", "").Replace("/", "") + ".txt";
strPath = strPath + "\\" + jsonwj;
string realPath = "/Map/" + jsonwj;
if (HttpContext.Current.Request.Url.Host == "localhost")
{
jsonPath = HttpContext.Current.Request.Url.Host +":20029"+ realPath;
}
else {
jsonPath = HttpContext.Current.Request.Url.Host + realPath;
}
StreamWriter fs = new StreamWriter(strPath, false, System.Text.Encoding.Default);
fs.Write(sbJson);
fs.Close();
}

posted @ 2017-10-25 09:40  牡丹  阅读(149)  评论(0)    收藏  举报