I want to retrieve data from Json file with webapi using Json file as data source.
In the controller, I have added following code:
Public HttpResponseMessage Get()
{
var json = File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath(@"~/App_Data\Bim.Json"));
return new HttpResponseMessage()
{
Content = new StringContent(json, Encoding.UTF8, "application/json"),
StatusCode = HttpStatusCode.OK
};
}
and in model,
public class bimModel
{
public string name { get; set; }
public string material { get; set; }
public string tag { get; set; }
public string contentType { get; set; }
}
Actually, I want to use a json file which is located in app_data folder, how to read data from JSON file? I am very new to the webApi, so it will be of great help if the experts can post the entire working code or as many details as possible, please.