欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# 读取.resx资源文件写入到json文件中

程序员文章站 2022-06-30 20:27:46
//调用ResXResourceReader类,需要引用System.Windows.Forms.dll,下同 ResXResourceReader resxReader = new ResXResourceReader(@"资源文件路径"); IDictionaryEnumerator dict ......

//调用resxresourcereader类,需要引用system.windows.forms.dll,下同

resxresourcereader resxreader = new resxresourcereader(@"资源文件路径");
idictionaryenumerator dict = resxreader.getenumerator();


stringbuilder jsonbuilder = new stringbuilder("{\"th_th\": {");
while (dict.movenext())
{
console.writeline("{0},{1}", dict.key, dict.value);
jsonbuilder.append("\"" + dict.key + "\":\"" + dict.value + "\",\n");
}
var jsonstring = jsonbuilder.tostring().substring(0, jsonbuilder.length - 2) + "}}";

var path = directory.getcurrentdirectory();

file.writealltext(path + "/th_th.json", regex.unescape(jsonstring));