从项目内的JSON文件读取 [英] Read from a JSON file inside a project

查看:462
本文介绍了从项目内的JSON文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF项目中有一个名为 Resources 的目录,并且在该目录中有一个 Settings.json . 我想从该文件中读取内容. 在文件设置中,我具有 Build Action-> Embedded Resource Copy to Output Directory-> Always Always 我这样读取文件:

I have a directory named Resources in my WPF project and I have a Settings.json inside that directory. I want to read content from that file. In file settings I have Build Action -> Embedded Resource and Copy to Output Directory -> Copy Always And I read the file like this :

using (StreamReader r = new StreamReader(@"/Resources/Settings.json"))

然后出现以下异常:

{找不到路径'C:\ Resources \ Settings.json'的一部分."}

{"Could not find a part of the path 'C:\Resources\Settings.json'."}

如何使它读取该目录中的文件?谢谢

How can I make this read the file in that directory? Thanks

推荐答案

using (StreamReader r = new StreamReader(Application.StartupPath + @"/Resources/Settings.json"))

这篇关于从项目内的JSON文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆