如何反序列化项目文件夹中本地存储的 json 文档的数据

How to deserialize the data of a json document stored locally in the project folder

一个 json 文件存储在项目中 folder.I 想要反序列化那个 json 的数据 document.Im 在获取 json 的路径时出错文档。

我使用了这段代码但出现错误 "An exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll but was not handled in user code"

        string file = HttpContext.Current.Server.MapPath("~/project.Services/xyz/myjsonfile.json");

            using (StreamReader reader = new StreamReader(file))
            {
              collection = JsonConvert.DeserializeObject<Dictionary<string, string>>(reader.ReadToEnd());             
           }

下面的代码对我有用

            using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(this.GetType().Assembly.GetName().Name + "." + filename))
         {using (StreamReader reader = new StreamReader(stream))
            {
                collection = JsonConvert.DeserializeObject<Dictionary<string, string>>(reader.ReadToEnd());
            }}

谢谢迈克尔