JSON을 간단한 텍스트 형식으로 반환하는 다음 작동 컨트롤러 메서드가 있습니다.ASP.NET 컨트롤러 메서드에서 JSON 반환
[HttpPost]
public IActionResult DecodeBarcode(string productCodeScheme, string productCode, string serialNumber, string batch, string expirationDate, int commandStatusCode) {
string TextAreaResult = string.Empty;
try {
TextAreaResult = string.Format("{0} {1} {2}", request.getHttpInformation(), request.getHttpWarning(), request.getHttpResponseCode());
} catch (Exception exc) {
TextAreaResult = "Exception: " + exc.Message;
}
return Json(TextAreaResult);
}
실행 위의 방법 후 출력 지금
"The pack is active No warning 200"
반면
request.getHttpInformation() is The pack is active
request.getHttpWarning() is No warning
request.getHttpResponseCode() is 200
같은 것을, 나는 이렇게 3 가지 키 - 값 쌍으로 응답을 분할하려고 보인다 내 반응은 다음과 같습니다.
{
httpInformation: "The pack is active",
httpWarning: "No Warning",
httpResponseCode: "200"
}
return Json(TextAreaResult)
전화에서 추가 매개 변수를 전달하는 방법은 무엇입니까?
내가 좋아하는 않는 경우가
[HttpPost]
public IActionResult DecodeBarcode(string productCodeScheme, string productCode, string serialNumber, string batch, string expirationDate, int commandStatusCode) {
string TextAreaResult = string.Empty;
string TextAreaResultHttpInformation = string.Empty;
string TextAreaResultHttpWarning = string.Empty;
string TextAreaResultHttpResponseCode = string.Empty;
try {
TextAreaResultHttpInformation = string.Format("{0}}", request.getHttpInformation());
TextAreaResultHttpWarning = string.Format("{1}}", request.getHttpWarning());
TextAreaResultHttpResponseCode = string.Format("{2}}", request.getHttpResponseCode());
} catch (Exception exc) {
TextAreaResult = "Exception: " + exc.Message;
}
return Json(TextAreaResultHttpInformation, TextAreaResultHttpInformation, TextAreaResultHttpResponseCode);
}
작동하지 않습니다 다음 어떻게 키 - 값 쌍을 구성하고 JSON으로 반환합니까? 아마도, Json
메서드는 여기에 올바른 선택이 아니지만 C#에 익숙하지 않아서 JSON을 구성하기위한 다른 C# inbuilt 메서드를 알지 못합니다.