How can I read JSON from a file stored locally?

前端 未结 2 1111
梦如初夏
梦如初夏 2021-02-08 05:38

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:

2条回答
  •  孤城傲影
    2021-02-08 06:20

    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>(sr.ReadToEnd());
    }
    

提交回复
热议问题