如何使用ASP.NET MVC将JSON数据存储和更新到文件中?
我想使用ASP.NET MVC将POST json数据存储并更新到一个文件中。我正在发送数据:如何使用ASP.NET MVC将JSON数据存储和更新到文件中?,asp.net,.net,angularjs,json,asp.net-mvc,Asp.net,.net,Angularjs,Json,Asp.net Mvc,我想使用ASP.NET MVC将POST json数据存储并更新到一个文件中。我正在发送数据: $http({ url: "AddMenus", dataType: 'json', method: 'POST', data: MenusInfo, headers: { "Content-Type": "application/json" } }); 添加菜单是一种操作方法,而MenusInfo是一个JSON对象 假设除了从请
$http({
url: "AddMenus",
dataType: 'json',
method: 'POST',
data: MenusInfo,
headers: {
"Content-Type": "application/json"
}
});
添加菜单是一种操作方法,而MenusInfo是一个JSON对象 假设除了从请求中读取JSON并按照问题中的要求更新该文件中包含的JSON之外,没有其他要求:
[HttpPost]
public ActionResult AddMenus()
{
// Get the raw json
Request.InputStream.Seek(0, SeekOrigin.Begin);
string jsonData = new StreamReader(Request.InputStream).ReadToEnd();
// Creates or overwrites the file with the contents of the JSON
System.IO.File.WriteAllText(@"C:\textfile.txt", jsonData);
}
假设除了从请求中读取JSON并按照问题中的要求更新该文件中包含的JSON之外,没有其他要求:
[HttpPost]
public ActionResult AddMenus()
{
// Get the raw json
Request.InputStream.Seek(0, SeekOrigin.Begin);
string jsonData = new StreamReader(Request.InputStream).ReadToEnd();
// Creates or overwrites the file with the contents of the JSON
System.IO.File.WriteAllText(@"C:\textfile.txt", jsonData);
}
好的,有什么问题吗?如何将json对象存储到文件中@曼尼什,你想和。嘿,普雷斯托!好的,有什么问题吗?如何将json对象存储到文件中@曼尼什,你想和。嘿,普雷斯托!