I am attempting to use JSON.Net to load in a JSON file stored locally on an ASP.Net MVC 4 site, but am having trouble pointing to the file. Here is what I am trying to do:
You are passing in the path and filename as your JSON payload. You need to open the file (eg. FileStream
) and read the contents into a variable (eg. StreamReader
) and pass the file contents as the payload to the deserializer.
You need to read in the JSON first using a FileStream
.
Try this.
using(StreamReader sr = new StreamReader(Server.MapPath("~/Content/treatments.json")))
{
treatments = JsonConvert.DeserializeObject<List<Treatment>>(sr.ReadToEnd());
}