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);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다