ich einen JSON-String Inhalt haben,nicht immer json Inhalt
[{
"id": 1,
"name": "Fort Craig Elementary",
"principal": "Michelle Thorne"
}]
und ich schreibe sehr einfache asp.net Web-API-Methode oben json zu bekommen,
[Route("api/schools")]
public HttpResponseMessage Get()
{
var json = HttpContext.Current.Server.MapPath("~/data/schools.json");
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(json, Encoding.UTF8, "application/json");
return response;
}
während ich bin schlagen URL "http://localhost:7602/api/schools", es ist mir Pfad von json statt json Inhalt,
c:\users\ajmal\documents\visual studio 2013\projects\Route\Route\data\schools.json
Bitte vorschlagen, wie json Inhalt zu erhalten.
Danke,
die Datei lesen und dann den Inhalt auf Antwortinhalt – rashfmnb
'MapPath' ist nur ein Weg, den Bau-Dienstprogramm. Es lädt den Inhalt dieser Datei nicht magisch herunter. – Nyerguds