확장자가 .json 인 JSON이 포함 된 파일이 있습니다. 나는 다음과 같이 파일을 제공하는 낸시를 사용하고 있습니다 :Jason에서 사용하기 위해 Nancy와 함께 Json 파일 반환
Get["/schema/{file}"] = parameters =>
{
return Response.AsFile(Directory.GetCurrentDirectory() + @"\sitefiles\schema\" + parameters.file as String);
}
을 나는이 같은 파일에 대한 jQuery를 아약스 요청을 만들 때 : 내가 파일을 다시 얻을
$.ajax({
url: "/schema/auditResponseSchema.json",
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (responseSchema) {
console.log("get response data - Success");
console.log(responseSchema);
},
timeout: 5000,
error: function (xmlObj, textStatus, errorThrown) {
console.log("get response data - failed. status:" + textStatus + " error:" + errorThrown);
}
});
을하지만로 인식되지 않습니다 JSON, 반환되는 Content-Type이 application/octet-stream이기 때문에 이것이 확실합니다.
to the Content-Type을 application/json으로 변경하려면 어떻게해야합니까?
나는 시도했다 :
// this returns "application/json in the content.
return Response.AsFile(Directory.GetCurrentDirectory() + @"\sitefiles\schema\" + parameters.file as String).Headers["Content-Type"] = "application/json";
// this returns the location of the file
return Response.AsJson(Directory.GetCurrentDirectory() + @"\sitefiles\schema\" + parameters.file as String);
내가 Response.AsJson를 문자열로 파일의 내용을 읽은 다음 사용하거나 헤더에게 Response.AsFile 반환을 변경할 수있는 방법이 있습니까?
대단히 감사합니다 스티븐,이 지금 문제를 해결했습니다. 나는 0.8을 볼 것이다. – Dave