Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用ASP.NET MVC将JSON数据存储和更新到文件中?_Asp.net_.net_Angularjs_Json_Asp.net Mvc - Fatal编程技术网

如何使用ASP.NET MVC将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对象 假设除了从请

我想使用ASP.NET MVC将POST 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对象存储到文件中@曼尼什,你想和。嘿,普雷斯托!