我想使用 ASP.NET MVC 将 POST json 数据存储和更新到文件中。我正在发送数据:
$http({
url: "AddMenus",
dataType: 'json',
method: 'POST',
data: MenusInfo,
headers: {
"Content-Type": "application/json"
}
});
Add Menus 是操作方法,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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句