다음과 같은 Nancy 모듈이 있습니다.낸시의 JSON 요청 본문을 문자열 원시 변수에 바인딩하는 방법은 무엇입니까?
public class MyFooTestModule : NancyModule
{
public MyFooTestModule()
{
Post["/text"] = _ =>
{
//string myNewText = this.Bind<string>(); // Fails, because string has no parameterless constructor
string myNewText = Request.Body.AsString();
return Response.AsJson(myNewText);
};
}
}
여기서 하나의 변수 string
에 바인딩하고 싶습니다. 내가 Request.Body.AsString()
대신, 캐릭터 제대로 작동하지 탈출 나는 여러 끝낼 사용하는 경우
System.MissingMethodException: No parameterless constructor defined for this object.
: 나는 예를 들어 this.Bind<int>()
을 사용 하듯이 런타임 동안 내가 예외가 말해 얻을 수 있기 때문에, 나는 this.Bind<string>()
을 사용할 수 없습니다 내 변수에서 따옴표 및 이스케이프 된 백 슬래시. 내가 클라이언트에서 자바 스크립트 문자열
"Hello\r\nWorld Foo!"
을 게시 할 때 더 정확하게
는, I는 서버로부터 에코 자바 스크립트 문자열
"\"Hello\\r\\nWorld Foo!\""
을받을 수 있습니다.
JSON 요청 본문을 프리미티브 string
변수에 바인딩하는 올바른 이유는 무엇입니까? 내 원시 자바 스크립트 클라이언트에서 사용되는 변수를 string
개의 변수로 바꾸기 위해 쓸모없는 컨테이너 클래스에 모든 기본 유형을 래핑하고 싶지 않습니다.